0

I am trying to add a unique body class using body_class filter if the role is a custom one via my plugin. I have a custom role called trip_vendor and the url for its profile page is abc.com/operator/tripvendor. Now, I want to add a custom body class if this url is visited. I have over-ridden the author.php from my plugin because the layout needs to be different. My code works in local but fails on live server. Body class as of the live server when the above url visited is hfeed full-width

Below is my code:

function vendor_body_class( $classes ) {
        global $post;
        $author = get_queried_object();
        if( is_author() )
        {
            if( end( $author->roles ) == 'trip_vendor' ){
               $classes[] = 'trip-vendor'; 
            }
        } 
        return $classes;
}
add_filter( 'body_class', 'vendor_body_class' );

This is how the author template is over-ridden from plugin:

$author = get_user_by( 'slug', get_query_var( 'author_name' ) );
if( is_object($author) )
{
   $role = $author->roles[0];
   if( is_author() )
   {
                if( 'trip_vendor' === $role )
                {
                    if ( $theme_file = locate_template( array ( 'author.php' ) ) ) {
                        $template_path = $theme_file;
                    } else {
                        $template_path = WP_TRAVEL_ENGINE_VENDOR_BASE_PATH . '/public/vendor-templates/profile/author.php';
                    }
                }
                return $template_path;
   }


}

Any help would be more than appreciable.

  • Do you use the same theme on both sites? – Krzysiek Dróżdż Mar 7 at 8:43
  • @KrzysiekDróżdż Yes both themes are same. The author template is over-ridden from my plugin. – saurav.rox Mar 7 at 8:48
  • Try with in_array() instead of end()? in_array( 'trip_vendor', $author->roles ). And maybe on the live server, the vendor_body_class() is not being called? A simple echo 'vendor_body_class'; in that function could confirm that. – Sally CJ Mar 9 at 2:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.