Skip to content →

Zihad Tarafdar Posts

Highlight WordPress nav menu item based on current post

wp_nav_menu() function automatically generates css class for styling current menu item or current menu ancestor item. But in both cases your current post/page/custom post type item has to be included in the navigation menu as top menu item or sub-menu item respectively. What if your single post/page/custom post type is not included in the navigation menu but you still want to highlight it’s post type? Let me give you an example. Lets assume we have a custom post type called “Event” and its archive page is included in our primary navigation menu as a Link. Whenever we will navigate to…

Leave a Comment

Redirect a specific user role to a different location after login in WordPress

A small yet very handy code snippet to redirect user to a different location by user role after a successful login in WordPress .   function zt_login_redirect( $redirect_to, $request, $user ) { // check if there is any user if ( is_array( $user->roles ) ) { // look for the specific user role we want to redirect i.e subscriber if ( in_array( ‘subscriber’, $user->roles ) ){ return home_url( ‘/your/redirect/location/’ ); } } } add_filter( ‘login_redirect’, ‘zt_login_redirect’, 10, 3 );  

Leave a Comment

WordPress Plugin: Smart Unread Comments Reloaded

There were two WordPress plugins out there which offered the feature for visitors to track unread comments since their last visit to a WordPress blog. One of them was smart unread comments developed by Brett Taylor & another one was by Ryan J parker. But unfortunately both the plugins are too old and none of the developers seemed to continue their support for their respective plugins. For my multi user blog I wanted to use one of them and chose Smart Unread Comments plugin. I have made some modifications to the plugin so that it becomes compatible with my WordPress…

One Comment