Custom Body Class Places Category

This topic contains 8 replies, has 4 voices, and was last updated by  Paolo 8 years, 6 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #364777

    C C
    Free User
    Post count: 3

    How would I go about adding a custom body class based on the Geodirectory Places Category ?

    Any help would be much appreciated.
    Thanks

    I’ve tried the following located on:
    https://wpgeodirectory.com/add-custom-body-classes-to-wordpress/

    
    
    function my_custom_body_class_in_category($classes) {
        // add 'my-class' to the my-category archive and single posts of the category. 
        if ( in_category( 'my-category' ) )
            $classes[] = 'my-class';
        // return the modified $classes array
        return $classes;
    }
     
    // add my custom class via body_class filter
    add_filter('body_class','my_custom_body_class_in_category');
    #364800

    Kor
    Moderator
    Post count: 16516

    Hi CC,

    Please share WP temp admin access to your site so we can take a better look. You can post the details here using the private reply option below.

    Thanks!

    #364808

    C C
    Free User
    Post count: 3
    This reply has been marked as private.
    #364838

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi CC,

    Are you trying to add a class to just place category archives? If so please check

    
    
    function my_custom_body_class_in_category($classes) {
    	// add 'my-class' to the my-category archive and single posts of the category.
    	if ( is_tax( 'gd_placecategory' ) )
    		$classes[] = 'my-class';
    	// return the modified $classes array
    	return $classes;
    }
    
    // add my custom class via body_class filter
    add_filter('body_class','my_custom_body_class_in_category');

    Thanks,

    Stiofan

    #364871

    C C
    Free User
    Post count: 3

    Hello Stiofan,
    Thanks for your response. You’ve pointed me in the right direction. Actually I was wanting to set the body class depending on which category the Place was in. Using the function

    is_tax('gd_placecategory', 'taxonomy term')

    For me the taxonomy term works so if my Places Category is for example “shops” then the following would detect the Category of ‘shops’ and insert the class of XXXshopsXXX in the body class.

    
    
    function my_custom_body_class_in_category( $classes ) {
        if ( is_tax( 'gd_placecategory','shops' ) ){
            $classes[] = 'XXXshopsXXX';
    	} elseif ( is_tax( 'gd_placecategory','stay' ) ){
    		 $classes[] = 'XXXstayXXX';
    	} elseif  ( is_tax( 'gd_placecategory','services' ) ){
    		$classes[] = 'XXXservicesXXX';
    	} else{
    		// do something else 
    	}
    		
        // return the modified $classes array
        return $classes;
    }
    add_filter( 'body_class','my_custom_body_class_in_category' );

    Thanks for your input !

    CC

    #364892

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Great! 🙂

    #364915

    Paolo
    Site Admin
    Post count: 31211

    Next time please avoid opening duplicate posts: https://wpgeodirectory.com/support/topic/custom-body-classes/

    Thanks

    #364977

    C C
    Free User
    Post count: 3
    This reply has been marked as private.
    #364989

    Paolo
    Site Admin
    Post count: 31211

    I think akismet flagged you 1st topic as spam somehow, no worries…

    Thanks for letting me know.

Viewing 9 posts - 1 through 9 (of 9 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount