Meta Title Tag

You don’t need to configure meta title tag. WordPress already has this featured! All we need to do is add theme support for title-tag.

add_theme_support( 'title-tag' );

We already do that hundreds times while coding themes. And WordPress does its job pretty well.

So, with Slim SEO, this feature is automatically enabled.

The title tag will have the following format:

  • For homepage: Site title – Site description
  • For singular pages/posts: Page/Post title – Site title
  • For other pages: Page title – Site title

How to change the meta title?

If you want to change the title, please use the pre_get_document_title filter provided by WordPress.

The following code changes the meta title for a single post with ID = 24. The title is get via a custom field:

add_filter( 'pre_get_document_title', function( $title ) {
if ( is_single( 24 ) ) {
$title = get_post_meta( get_the_ID(), 'field_id', true );
return $title;
} );