Skip to:

Filter activity posts by language

  • DragoWeb



    It’s been a while since I’m looking for a simple way to filter the activity posts according to the language displayed when publishing. Actually, when we manage a site in multiple languages (via WPML, Polylang, or other) the problem is that all the activity publications in all different languages are mixed on the same page. A simple solution would be to add a class for each li element.

    So, we start by identifying the language of the page when we click on “Post update”:

    $lang = get_bloginfo('language');

    then we inject it into the database so that it appears as a class on each li element (activity-en_US ; activity-fr_FR…)

    Then we just have to add a CSS line like li.activity-en_US, body.en li.activity-fr_FR { display: none; }

    An of course, we have to add a language class for body via body_class, (like this, if you use WPML, for example) in the functions.php child theme.

    `function body_class_language( $classes ) {
    if ( ICL_LANGUAGE_CODE == ‘en’ ) {
    $classes[] = ‘en’;
    } elseif ( ICL_LANGUAGE_CODE == ‘en’ ) {
    $classes[] = ‘en’;
    return $classes;
    add_filter(‘body_class’, ‘body_class_language’);`

    Is it possible? Can anyone help me with this? Or maybe you have a better idea or solution to solve this? I know HTML/CSS very well, but I’m still struggling with PHP/SQL 😅 Thanks

  • You must be logged in to reply to this topic.
Skip to toolbar