Home›Support›English Support›[Waiting for user confirmation] Function that adds a class to the body tag of each page based on the page slug is not working in tra...
[Waiting for user confirmation] Function that adds a class to the body tag of each page based on the page slug is not working in tra...
This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
Background of the issue:
In the site I'm working on (hidden link) we use a function to add the page slug as a class to the body tag, to help with page-specific styling. However, in the WPML translated versions, the function does not create the class and add it to the body tag. This is the function: function add_slug_body_class( $classes ) { global $post; if ( isset( $post ) ) { $classes[] = $post->post_type . '-' . $post->post_name; } return $classes; } add_filter( 'body_class', 'add_slug_body_class' );
Symptoms:
The function that adds a class to the body tag based on the page slug is not working in WPML translated versions, causing styles to break.
Questions:
How can I ensure that the function works in the translated versions?
Note that I have not tested this snippet yet. Please make sure to take a backup of your website before running any tests and to have FPT access available in case you need to undo the changes.