- This topic has 6 replies, 2 voices, and was last updated 3 years, 10 months ago by Tom.
-
AuthorPosts
-
May 27, 2020 at 8:34 am #1303711onalti
Hello, it adds the category names as post class. I use the wpml translation plugin, and I want to define the translated article category names as the main language names. Is there a filter I can use for this?
I hope I can explain my problem, thank you.<article id=”post-<?php the_ID(); ?>” <?php post_class(); ?> <?php generate_do_microdata( ‘article’ ); ?>>
<article id=”post-31379″ class=”post-31379 result type-result status-publish has-post-thumbnail hentry portfolio_category-fotos masonry-post generate-columns tablet-grid-50 mobile-grid-100 grid-parent grid-33 resize-featured-image masonry-brick” itemtype=”https://schema.org/” itemscope=”” style=”position: absolute; left: 0%; top: 56px;”>
<article id=”post-31379″ class=”post-31379 result type-result status-publish has-post-thumbnail hentry portfolio_category-photo masonry-post generate-columns tablet-grid-50 mobile-grid-100 grid-parent grid-33 resize-featured-image masonry-brick” itemtype=”https://schema.org/” itemscope=”” style=”position: absolute; left: 0%; top: 56px;”>
I want to use the same definition in translated categories. Let them all be in the mother tongue.
May 27, 2020 at 9:07 am #1303770onaltiI found this for the wmpl translation plugin. but I couldn’t apply.
I need to add the same CSS class to <body> element of all translatons of a page, but the CSS class added with body_class() is different for each translation because it is taken from the translated title of the page.
For example, for about us page I get this markup:
<body class=”about-us”> // English
<body class=”sobre-nosotros”> // Spanish
I want to get the same class for both languages:<body class=”about-us”> // English
<body class=”about-us”> // Spanish
Is there a way to add the same CSS class for all translations of the same page?function add_default_language_slug_class( $classes ) { global $post; if ( isset( $post ) ) { $default_language = wpml_get_default_language(); // will return languague code of your default language for example 'en' // get the post ID in default language $default_post_id = icl_object_id($post->ID, 'post', FALSE,$default_language); // get the post object $default_post_obj = get_post($default_post_id); // get the name $default_post_name = $default_post_obj->post_name; // add default language post name to body class $classes[] = $default_post_name; } return $classes; } add_filter( 'body_class', 'add_default_language_slug_class' );
May 27, 2020 at 3:58 pm #1304183TomLead DeveloperLead DeveloperHi there,
This is likely something you need to ask WPML support. I’m not familiar enough with their functions to know how to do it.
It looks like you’re on the right track, you just need to right functions which they should be able to help with π
May 27, 2020 at 4:12 pm #1304193onaltiHi thank you for the answer.
yes I will get support from WPML but generatepress
Is there a general filter for post_class();May 28, 2020 at 9:33 am #1305300TomLead DeveloperLead DeveloperYes, there’s a
post_class
filter as well as abody_class
filter – both are core WP filters πMay 28, 2020 at 11:48 am #1305454onaltithank you π
May 28, 2020 at 2:18 pm #1305609TomLead DeveloperLead DeveloperNo problem π
-
AuthorPosts
- You must be logged in to reply to this topic.