How to get menu location in wp_update_nav_menu hook

get_nav_menu_locations will give you menu IDs keyed by location which should correspond to the $id also passed with wp_update_nav_menu. add_action(‘wp_update_nav_menu’, function ($id, $data = NULL){ foreach( get_nav_menu_locations() as $location => $menu_id ){ if( $id == $menu_id ){ echo ‘location is ‘ . $location; } } }, 10, 2);

Using wordpress translations strings in plugin

Turns out that wordpress uses context strings for this piece of text: _x(‘Add New’, ‘post’) and _x(‘Add New’, ‘page’) This is because the string ‘Add New’ is different depending on the following noun in some languages. i.e in Danish: ‘Add New Post’ => ‘Tilføj Nyt Indløg’ ‘Add New Page’ => ‘Tilføj Ny Side’. Notice the … Read more

How can I modify admin bar only if my plugin is loaded

You need to remember screen id of your page and check current screen id before adding new menu item: add_action( ‘admin_menu’, ‘my_plugin_menu’ ); function my_plugin_menu() { global $my_swell_plugin_page; $my_swell_plugin_page = add_menu_page( ‘My Swell Plugin’, ‘My Swell Plugin’, ‘edit_posts’, ‘blah’, ‘generate_main_page’ ); } function generate_main_page() { //We are definitely in our plugins page now – let’s … Read more

Meta query for comparing two dates

EDIT start and end date is following the date format. But you are using NUMERIC type casting in meta query. You need to use DATE type like array( ‘key’ => ‘user_registered’, ‘value’ => $start_date, ‘compare’ => ‘>’, ‘type’ => ‘DATE’ ), array( ‘key’ => ‘user_registered’, ‘value’ => $end_date, ‘compare’ => ‘<=’, ‘type’ => ‘DATE’ ) … Read more

Hide a Menu Item on Login

Can’t you change CSS rules? .hide-item-not-login{ display: block !important; } .logged-in .hide-item-not-login{ display: none !important; } EDIT To add login/logout menu item, you will need to add one more class to logout menu item. Let’s say you added class .logout-link to logout menu item. Then you can add css like this. .hide-item-not-login{ display: block !important; … Read more