Hi there
What is the function to add the page name to the body class?
Thanks
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
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
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
Hi there
is this still correct? My new version of Enfold doesnt work with this function anymore?
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