Remove version parameters from WordPress javascript and css urls

In WordPress version number are append to javascript and css url. you can see these in browser by press ‘Ctrl+U’ or right click on web page then click on ‘View page source’. Continue reading “Remove version parameters from WordPress javascript and css urls”

Advertisements

Add post id to admin column in WordPress

Following example will shows how to add a custom column ‘ID’ in WordPress post.

To add a custom column for page ,  post in WordPress use ‘manage_post_posts_columns’ filter. I create a function named wp_add_post_ids_to_columns() which called via ‘manage_post_posts_columns’ filter to add column. Continue reading “Add post id to admin column in WordPress”

Dynamically add login/logout link to a WordPress menu

Using ‘wp_nav_menu_items’ filter we can modify wordpress menu and able to add or remove links.Following code will add dynamic login and logout link to a wordpress menu which primary location is ‘topmenu’.

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

function wp_login_logout($items, $args) {
 if($args->theme_location =='topmenu'):

 if (is_user_logged_in()) {
 $items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
 } else {
 $items .= '<li><a href="'. wp_login_url(get_permalink()) .'">Log In</a></li>';
 }
 return $items;
 endif;
 
return $items;
}

You just need to add above code in your functions.php file and its working fine!