Archive

Posts Tagged ‘problem wordpress’

Add menu into wordpress page

May 11, 2011 Leave a comment

Hello Folks,

Since many days i was wondering to add a dynamic menus that i could insert via plugin. I wanted to insert login and logout buttons into menu bar without editing the template. Then i found out one hook for the wordpress that i could inject my content into menu.

      add_filter('wp_nav_menu_items',add_menu,10,2);

The above hook will call add_menu which contain 2 parameters.

      function add_menu($items,$args)
      {
            items .= "<li>Another Menu</li>";
            return items;
      }

it will look as following


As you can see another menu is created beside. As css is not applied it looks like that apply css would
look alike.

If there is any problem give a reply.

Advertisements

Auto save problem for custom variables

April 14, 2011 2 comments

Readers while developing with wordpress i found a problem with the post . I had custom variable into my metabox.

So there is a default hook to be called to save that custom variable into the database.

add_action('save_post','function_save_var');

So by default when u click publish post or update post then ‘function_save_var’ would be called .
So when u update the post and then close the page then this would work perfectly fine but then i din know
auto save would call this hook too .

So when my page would be open for a while all my values would reset and my functionality would fail. So
after a little search i got the solution.

function function_save_var()
{
       // Function without avoiding auto save.
}

The above function would fail as it would reset everything .

but then to avoid; you need to add the following code in the start of the function

if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
        return $post_id;

if the post will autosave this would directly return n do not update anything . Thus this is all solved.

%d bloggers like this: