This thread is resolved. Here is a description of the problem and solution.
Problem:
The function intended to add a page slug as a class to the body tag does not work on WPML translated versions of the site, causing issues with page-specific styling.
Solution:
To ensure the function works with WPML translated versions, you need to modify the function to use WPML's hooks for managing translations. Here is a step-by-step guide:
function add_slug_body_class_wpml_fallback( $classes ) { $original_id = get_queried_object_id(); // Check if WPML is available if ( class_exists( 'sitepress' ) ) { $current_lang = apply_filters( 'wpml_current_language', null ); $translated_id = wpml_object_id( $original_id, 'page', true, $current_lang ); } else { $translated_id = $original_id; } // WPML logic continues if ( $translated_id ) { $post_type = get_post_type( $translated_id ); $post_slug = get_post_field( 'post_name', $translated_id ); if ( $post_type && $post_slug ) { $classes[] = $post_type . '-' . $post_slug; } } return $classes; } add_filter( 'body_class', 'add_slug_body_class_wpml_fallback' );
Before implementing this solution, ensure to back up your site and have FTP access ready as a precaution. This modification involves developer-level changes, which are usually beyond standard support scope. For more details on WPML's hooks, visit WPML Hooks Reference.
If this solution does not apply to your case, or if it seems outdated, we recommend opening a new support ticket. Also, check related known issues at https://wpml.org/known-issues/, verify the version of the permanent fix, and confirm that you have installed the latest versions of themes and plugins. For further assistance, please visit our support forum.
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.
This topic contains 1 reply, has 0 voices.
Last updated by 3 weeks, 1 day ago.
Assisted by: Andreas W..