0

I need to add something after title in loop in single post and page, home page, categories. This is for a plugin and i don't want to modify the theme directly.

function after_title($title) {

       if (!is_admin() || is_single() || is_page() || is_home() || is_category() ) {

            $write = 'AFTER TITLE';
            $after_title = $title.$write;
            return $after_title ;

            }

      }
add_filter( 'the_title', 'after_title' );

But it add content everywhere, in the widget or sidebare loop and even in my menu. I just want to do it in the main content, not everywhere.

I also tryed other ways but i had the same problems.

add_action('the_post', 'atr_insert'); 
add_action('the_content', 'atr_insert');
1

Use in_the_loop() to know if you are currently in the loop of the main query.

function after_title($title) {
    if ( in_the_loop() && ( is_single() || is_page() || is_home() || is_category() ) ) {
        $write = 'AFTER TITLE';
        $title = $title.$write;
    }
    return $title;
}
add_filter( 'the_title', 'after_title' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.