Site logo

[Resolved] When automatically adding prefix in post articles, get them in the top menu too

Home Forums Support [Resolved] When automatically adding prefix in post articles, get them in the top menu too

Home Forums Support When automatically adding prefix in post articles, get them in the top menu too

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #2531422
    Eric

    Hi
    I use this to automatically profixe my post titles depending on the category or the tag they are assigned.
    It works fine, except for the menu items which are impacted too.
    As one can see here : https://yogaazur.fr/cancer-nice-meditation/
    or here : https://yogaazur.fr/tag/pranayama/

    function my_modified_title($title, $id) {
      if (in_category('evennement')) return '📌'.$title;
      if (has_tag    ('video'))      return '▶️'.$title;
      if (has_tag    ('citation'))   return '🗣'.$title;
      if (has_tag    ('meditation')) return '🧘🏻'.$title;
      return $title;
    }
    add_filter('the_title', 'my_modified_title', 10, 2);

    Does anyone see where this come from?
    Thank you
    Eric

    #2531466
    Eric

    PS. I have added this but the issue is still the same…

    add_filter('the_title', 'iSt101_modify_all_titles', 10, 2);
    
    function iSt101_modify_all_titles($title, $id) {
    	
        // Vérifie si la fonction est appelée dans le contexte d'affichage des menus
        if (in_the_loop() || is_admin()) {
            return $title;
        }
    	
      if (in_category('evennement')) return '📌'.$title;
      if (has_tag    ('video'))      return '▶️'.$title;
      if (has_tag    ('citation'))   return '🗣'.$title;
      if (has_tag    ('meditation')) return '🧘🏻'.$title;
      return $title;
    }
    #2531484
    David
    Staff
    Customer Support

    Hi there,

    try this:

    function change_title($title) {
        if( in_the_loop() ) {
            if (in_category('evennement')) return '📌'.$title;
            if (has_tag('video'))      return '▶️'.$title;
            if (has_tag('citation'))   return '🗣'.$title;
            if (has_tag('meditation')) return '🧘🏻'.$title;            
        }    
        return $title;    
    }
    add_filter('the_title', 'change_title', 10, 2); 
    
    #2531495
    Eric

    Many many thanks David!

    #2531503
    David
    Staff
    Customer Support

    You’re welcome

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.