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' );
Code language: JavaScript (javascript)

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 meta title manually?

If you want to set custom meta title for a specific post or term, simply enter the text in the Search Engine Optimization meta box below the content area:

Edit meta title manually in Slim SEO
Search Engine Optimization meta box

You'll see the status icon showing if the description has a good length. The meta title should not be longer than 60 characters.

Note that, the manual meta title is not truncated. It's always shown as it is.

As the plugin supports shortcodes, you can simply add your own shortcodes here to output your custom dynamic content.

How to change the meta title with code?

If you want to change the title, please use the slim_seo_meta_title filter.

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

add_filter( 'slim_seo_meta_title', function( $title ) { if ( is_single( 24 ) ) { $title = get_post_meta( get_the_ID(), 'field_id', true ); } return $title; } );
Code language: PHP (php)

Please note that if you set your homepage as a static page, then the plugin treats it like a normal page.

How to hide SEO settings meta box for non-admin users?

In some cases, where you want only admins can change the meta title, meta description or other SEO settings, then use this snippet to hide the SEO settings meta box from other user roles:

// Hide SEO settings meta box for posts. add_action( 'add_meta_boxes', function() { if ( current_user_can( 'manage_options' ) ) { return; } $context = apply_filters( 'slim_seo_meta_box_context', 'normal' ); remove_meta_box( 'slim-seo', null, $context ); }, 20 ); // Hide SEO settings meta box for terms. add_action( 'init', function() { if ( current_user_can( 'manage_options' ) ) { return; } global $wp_filter; $hook = $wp_filter['init']; $callbacks = $hook->callbacks[99]; foreach ( $callbacks as $callback ) { if ( ! is_array( $callback['function'] ) ) { continue; } $function = $callback['function']; if ( $function[0] instanceof \SlimSEO\MetaTags\Settings\Term && $function[1] === 'register_hooks' ) { remove_action( 'init', $function, 99 ); return; } } } );
Code language: PHP (php)