and tags? * Is there a call to wp_title()? * There can't be any hardcoded text in the tag. * * See: http://make.wordpress.org/themes/guidelines/guidelines-theme-check/ */ class Title_Checks implements themecheck { protected $error = array(); function check( $php_files, $css_files, $other_files ) { $ret = true; $php = implode( ' ', $php_files ); // Look for add_theme_support( 'title-tag' ) first $titletag = true; if ( ! preg_match( '#add_theme_support\s?\(\s?[\'|"]title-tag#', $php ) ) { $this->error[] = '<span class="tc-lead tc-required">'.__('REQUIRED','theme-check').'</span>: '.__('No reference to <strong>add_theme_support( "title-tag" )</strong> was found in the theme.', 'theme-check' ); $titletag = false; $ret = false; } // Look for <title> and tags. checkcount(); if ( ( 0 <= strpos( $php, '' ) || 0 <= strpos( $php, '' ) ) && !$titletag ) { $this->error[] = '' . __( 'REQUIRED', 'theme-check').': ' . __( 'The theme must not used the <title> tags.', 'theme-check' ); $ret = false; } // Check whether there is a call to wp_title() checkcount(); if ( 0 <= strpos( $php, 'wp_title(' ) && !$titletag ) { $this->error[] = '' . __( 'REQUIRED', 'theme-check').': ' . __( 'The theme must not call to wp_title().', 'theme-check' ); $ret = false; } //Check whether the the tag contains something besides a call to wp_title() checkcount(); foreach ( $php_files as $file_path => $file_content ) { // Look for anything that looks like <svg>...</svg> and exclude it (inline svg's have titles too) $file_content = preg_replace('/<svg.*>.*<\/svg>/s', '', $file_content); // First looks ahead to see of there's <title>... // Then performs a negative look ahead for wp_title(...); if ( preg_match( '/(?=(.*)<\/title>)(?!<title>\s*<\?php\s*wp_title\([^\)]*\);?\s*\?>\s*<\/title>)/s', $file_content ) ) { $this->error[] = '<span class="tc-lead tc-required">' . __( 'REQUIRED', 'theme-check').'</span>: ' . __( 'The <strong><title></strong> tags can only contain a call to <strong>wp_title()</strong>. Use the <strong>wp_title filter</strong> to modify the output', 'theme-check' ); $ret = false; } } return $ret; } function getError() { return $this->error; } } $themechecks[] = new Title_Checks;