Skip to main content
deleted 20 characters in body
Source Link
Stephen Harris
  • 32.6k
  • 6
  • 84
  • 118

I believe checking in_the_loop will work for the main query:

function custom_title( $title ) {
    global $post, $wp_query;$post;
    $text = 'Extra text: ';

    if ( get_post_type( $post->ID ) == 'custom_post_type' && $wp_query->in_the_loopin_the_loop() ){
        return $text . $title;
    }
    else {
        return $title;
    }
}

add_filter( 'the_title', array($this, 'custom_title' ) );

I believe checking in_the_loop will work for the main query:

function custom_title( $title ) {
    global $post, $wp_query;
    $text = 'Extra text: ';

    if ( get_post_type( $post->ID ) == 'custom_post_type' && $wp_query->in_the_loop ){
        return $text . $title;
    }
    else {
        return $title;
    }
}

add_filter( 'the_title', array($this, 'custom_title' ) );

I believe checking in_the_loop will work for the main query:

function custom_title( $title ) {
    global $post;
    $text = 'Extra text: ';

    if ( get_post_type( $post->ID ) == 'custom_post_type' && in_the_loop() ){
        return $text . $title;
    }
    else {
        return $title;
    }
}

add_filter( 'the_title', array($this, 'custom_title' ) );
Source Link
Milo
  • 78.8k
  • 4
  • 127
  • 168

I believe checking in_the_loop will work for the main query:

function custom_title( $title ) {
    global $post, $wp_query;
    $text = 'Extra text: ';

    if ( get_post_type( $post->ID ) == 'custom_post_type' && $wp_query->in_the_loop ){
        return $text . $title;
    }
    else {
        return $title;
    }
}

add_filter( 'the_title', array($this, 'custom_title' ) );