The-seo-framework: Title for Custom Post Type Archive pages

Created on 17 Apr 2017  Â·  3Comments  Â·  Source: sybrew/the-seo-framework

Is there anything that will allow me to set the title of a custom post type archive page similar to the filter descriptions given in #26 - Meta Description for Custom Post Type Archive pages

Most helpful comment

For feature references, since the code above didn't work for me.

Set custom post type archive titles – https://theseoframework.com/docs/api/filters/

add_filter( 'the_seo_framework_title_from_generation', function( $title= '', $args = [] ) {
    /** 
     * @link https://developer.wordpress.org/reference/functions/is_post_type_archive/
     */
    if ( is_post_type_archive( 'my_post_type_name' ) ) {
        $title = 'My custom title';
    }

    return $title;
}, 10, 2);

All 3 comments

It still requires development.

In the meantime, you can use the exact same filter as you've found here:
https://github.com/sybrew/the-seo-framework/issues/26#issuecomment-248559457

But, because WordPress also handles the title, it will be slightly different.

Alter social titles:

add_filter( 'the_seo_framework_ogtitle_output', 'my_special_title', 10, 2 );
add_filter( 'the_seo_framework_twittertitle_output', 'my_special_title', 10, 2 );
/**
 * Alters the title on special conditions.
 *
 * @param string $title The current title.
 * @param int $id The Post, Page or Term ID.
 * @return string Title. Does not need to be escaped.
 */
function my_special_title( $title= '', $id = 0 ) {

    /** 
     * @link https://developer.wordpress.org/reference/functions/is_post_type_archive/
     */
    if ( is_post_type_archive( 'my_post_type_name' ) ) {
        $title = 'My super title';
    }

    return $title;
}

Alter all titles:

add_filter( 'the_seo_framework_pro_add_title', 'my_special_page_title', 10, 3 );
/**
 * Alters the title on special conditions.
 *
 * @param string $title The current title.
 * @param array $args The title generation arguments.
 * @param bool $escape Whether the title is being escaped.
 * @return string Title. Does not need to be escaped.
 */
function my_special_page_title( $title= '', $args = array(), $escape = true ) {

    /** 
     * @link https://developer.wordpress.org/reference/functions/is_post_type_archive/
     */
    if ( is_post_type_archive( 'my_post_type_name' ) ) {
        $title = 'My super title';
    }

    return $title;
}

For feature references, since the code above didn't work for me.

Set custom post type archive titles – https://theseoframework.com/docs/api/filters/

add_filter( 'the_seo_framework_title_from_generation', function( $title= '', $args = [] ) {
    /** 
     * @link https://developer.wordpress.org/reference/functions/is_post_type_archive/
     */
    if ( is_post_type_archive( 'my_post_type_name' ) ) {
        $title = 'My custom title';
    }

    return $title;
}, 10, 2);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

alpipego picture alpipego  Â·  4Comments

sybrew picture sybrew  Â·  6Comments

epgunn picture epgunn  Â·  3Comments

themightyant picture themightyant  Â·  4Comments

paaljoachim picture paaljoachim  Â·  5Comments