questions

Add Text to WordPress Post Title, Exclude From Menu

Rate this post

I am using the Avada theme for WordPress and wanted to add “…” after each WordPress title, but the code I found adds “…” after the menu text. How can I exclude the menu from being added as well?

/* Adds ... After Blog Titles */

function add_suffix_to_title($title, $id = null){
    if (! is_admin()) {
        return ''.$title.'...';
    }
    return $title;
}

add_action( 'the_title', 'add_suffix_to_title', 10, 1 );

Thank you in advance!

 

✔️Solution:

You need to add some more condition to exclude menu, like bellow:

function add_suffix_to_title($title, $id = null){
    
        if (! is_admin()) {
            
            if(is_singular(array('post','page')) || is_archive() || is_home()){
                
                if(in_the_loop()){
                    
                    return $title . '...';
           
                }
            }
    
        }
        
        return $title;
    }
    
add_action( 'the_title', 'add_suffix_to_title', 10, 1 );

Leave a Reply

Your email address will not be published.

Back to top button