How to Fix Underscore Theme Title Error with Theme-Check Plugin

Fix Underscore Theme Error with Theme-Check Plugin

If you are using a WordPress theme based on old “underscores” theme, when you try to check your theme using “Theme-Check” plugin you will see this message:

The <title> tags can only contain a call to wp_title(). Use the wp_title filter to modify the output

Look at the image:

Fix Underscore Theme Error with Theme-Check Plugin

You can fix this problem editing inc/extras.php file. Open extras.php and find this:

if ( ! function_exists( '_wp_render_title_tag' ) ) :
	/**
	 * Title shim for sites older than WordPress 4.1.
	 *
	 * @link https://make.wordpress.org/core/2014/10/29/title-tags-in-4-1/
	 * @todo Remove this function when WordPress 4.3 is released.
	 */
	function themeslug_render_title() {
		echo '<title>' . wp_title( '|', false, 'right' ) . "</title>\n";
	}
	add_action( 'wp_head', 'themeslug_render_title' );
endif;

Replace it with:

if ( ! function_exists( '_wp_render_title_tag' ) ) :
	function themeslug_render_title() {
		?>
		<title><?php wp_title( '|', true, 'right' ); ?></title>
		<?php
	}
	add_action( 'wp_head', 'themeslug_render_title' );
endif;

Save extra.php file and check your theme again with “Theme-Check” plugin. Above error message will not be displayed again.