[+] Add the WPML LS in Posts only

This code will prevent rendering the language switcher if the current post type is not a “post” or a “product”: of course, you can customize it based on your needs.

Add this to functions.php:

<pre>

function remove_wpml_post_alternative_languages( $html ) {
   $allowedPostTypes = [
      'post',
      'product',
   ];

   if ( ! in_array( get_post_type(), $allowedPostTypes, true ) ) {
      return '';
   }

   return $html;
}

add_filter( 'wpml_ls_post_alternative_languages', 'remove_wpml_post_alternative_languages' );

</pre>


Let us know if this snippet is not working for you:

This snippet doesn’t work
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments