• Resolved wbrobston

    (@wbrobston)


    Hello,

    I would like to append a meta field value to the meta titles for a specific post type.

    For example:

    Meta Title: Page Title – Meta Field1 – Site Title

    Is this possible?
    Thanks very much,
    William

Viewing 1 replies (of 1 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hi William,

    We planned to add this as a feature long ago, but I never got around to implementing it.

    In the meantime, you can do this with filters. You need to replace the my_meta_key part with the meta key you wish to retrieve.

    add_filter( 'the_seo_framework_title_from_generation', function( $title, $args ) {
    
    	$post_id = 0;
    
    	if ( null === $args ) {
    		// In the loop.
    		if ( is_singular() )
    			$post_id = get_queried_object_id();
    	} elseif ( ! $args['pta'] && ! $args['taxonomy'] ) {
    		// Singular custom query (admin inputs, SEO Bar, etc.)
    		$post_id = $args['id'];
    	}
    
    	$post_type = $post_id ? tsf()->get_post_type_real_ID( $post_id ) : '';
    
    	if ( 'my_post_type' === $post_type ) {
    		$post_meta = get_post_meta( $post_id, 'my_meta_key', true );
    
    		if ( $post_meta )
    			$title .= "– $post_meta";
    	}
    
    	return $title;
    }, 10, 2 );

    To learn where to implement filters, please see https://tsf.fyi/docs/filters#where.

    • This reply was modified 2 years, 9 months ago by Sybre Waaijer. Reason: More robust checking in filter
Viewing 1 replies (of 1 total)
  • The topic ‘Can I intert a meta field into the meta title for a specific post type?’ is closed to new replies.