Archived topic
When automatically adding prefix in post articles, get them in the top menu too
4 replies · Started by Eric on February 13, 2023
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
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;
}
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);
Many many thanks David!
You're welcome