Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #417055

    Hi there
    What is the function to add the page name to the body class?
    Thanks

    #417142

    Hey reddishpinkmedia!

    Thank you for using our theme.

    To add your custom classes to the body you can use a filter.

    See https://codex.wordpress.org/Function_Reference/body_class and look for the Topic “Add Classes By Filters”.

    Put the code in functions,.php of Enfold or of the Child theme.

    Come back with further questions.

    Cheers!
    Günter

    #417325

    hey thanks!
    I tried this code

    // Add specific CSS class by filter
    add_filter( ‘body_class’, ‘my_class_names’ );
    function my_class_names( $classes ) {
    // add ‘class-name’ to the $classes array
    $classes[] = ‘class-name’;
    // return the $classes array
    return $classes;
    }

    But that doesnt work. It looks like it adds a class name anyway. I need the page name. Is this right?
    http://franklydifferent.com/enfold

    #417681

    Hi!

    Thank you for coming back.

    The code above always adds the class ‘class-name’.

    Try to replace the code above with:

    
    // Add specific CSS class by filter
    add_filter( 'body_class', 'my_class_names' );
    function my_class_names( $classes ) 
    {
    	global $post;
    	
    	// add 'post_name' to the $classes array 
    	$classes[] = $post->post_name;
    	// return the $classes array
    	return $classes;
    }
    

    You must use post_name because the title might contain spaces

    Best regards,
    Günter

    #629116

    Hi there
    is this still correct? My new version of Enfold doesnt work with this function anymore?

    #630021

    Hi,


    @reddishpinkmedia
    what exactly is the error you are getting? I tried it on my local installation and yes, it does work fine still.

    Best regards,
    Yigit

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.