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

    This message does not help track down the actual problem. Would you consider adding a link to the file?

    // Get correct URL and path to wp-content
    $content_url = untrailingslashit( dirname( dirname( get_stylesheet_directory_uri() ) ) );
    $content_dir = untrailingslashit( dirname( dirname( get_stylesheet_directory() ) ) );
    foreach ( $php_files as $file_path => $file_content ) {
    	if ( preg_match( '/(?=<title>(.*)<\/title>)(?!<title>\s*<\?php\s*wp_title\([^\)]*\);\s*\?>\s*<\/title>)/s', $file_content ) ) {
    		// Fix path on Windows
    		$file_path = str_replace( '\\', '/', $file_path );
    		$content_dir = str_replace( '\\', '/', $content_dir );
    		$url = str_replace( $content_dir, $content_url, $file_path );
    
    		$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' ) . sprintf(' in <a href="%s">%s</a>', $url, basename($file_path));
    		$ret = false;
    	}
    }

    https://www.ads-software.com/plugins/theme-check/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    The title tags are almost universally in your header.php file. But honestly, you created the theme and you don’t know where your title tags are? Use an editor with good global searching.

    Thread Starter Jesse Graupmann

    (@jgraup)

    I use PHPStorm and I’m aware of where title tags should be and how to use global search, honestly. But you built a helpful tool and can’t recognize bad UX? Ok, moving on…

    The original point is; Some of your functions give line numbers which is super helpful while a few do not. wp_title, wp_head, and wp_footer all say they are REQUIRED but don’t give any information to get straight to the issue they found.

    I’m following https://codex.www.ads-software.com/Plugin_API/Filter_Reference/wp_title and I’m still getting wp_title errors. In a global search everything looks fine to me, until I added the file references. Now it’s telling me there is a problem in files that looked just fine.

    <title><?php wp_title ('|', true, 'right'); ?></title>

    Can you spot the problem? There is a single space between wp_title and (. This seems like a false positive because the correct format is;

    <title><?php wp_title('|', true, 'right'); ?></title>

    My suggestion is; If you have an error, give a line reference or even a file ref for all cases — especially REQUIRED issues.

    Plugin Author Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    According to the WP coding standards, the correct way to do that would be:

    <title><?php wp_title( '|', true, 'right' ); ?></title>

    Not saying I agree with the code standards, but hey.

    Anyway, as far as title tags go, you’re better off using the core title tag support nowadays, by using add_theme_support( 'title-tag' );. This takes care of the whole thing for you and you can leave out the title entirely.

    https://codex.www.ads-software.com/Title_Tag

    I’m not entirely sure what line number you would expect to be given for the case where something like a wp_head() call is simply missing. It points you to a codex article on the topic for more information now. I suppose it could search for the /head and tell you to add it there, but the codex article gives somewhat more information. Could be better written there, perhaps.

    As for your specific case, the problem isn’t the line-number, but the fact that the regex doesn’t recognize the extra space. That’s a valid bug, but I’d first try to fix the regex, not to add more verbose output.

    Thread Starter Jesse Graupmann

    (@jgraup)

    Thank-you for taking a minute to review this, I appreciate it.

    After looking at title-tag it definitely makes sense over wp_title.

    As for errors with wp_title(), wp_head() and wp_footer, a major issue in your plugin is that errors can be condensed. Three files may report the same problem but together they receive only one line in the report.

    I would suggest for those issues, the filename and/or path to the file is very useful.

    In the case of wp_head() & wp_footer I am seeing “Could not find wp_head.” but I have no idea which file it’s referring to. And because it doesn’t exist it’s not something I can search for. I have multiple variations of headers but only a single footer file that contains wp_footer(). I clearly see wp_footer() in my footer.php so to me that error is utter BS — unless I am just not seeing the file it’s referring too (which might not be footer.php???).

    For cases where it says I am missing something, I want to see the file it is referring to.

    For cases where I am doing something wrong, I want to see the file + line number it is referring to.

    This theme was never meant to be submitted anywhere. Regardless, your plugin is the absolute best tool to catch potential errors. I believe with a little extra reporting you could save a ton of extra work by the end user.

    Plugin Author Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    For cases where it says I am missing something, I want to see the file it is referring to.

    Well, that’s sort of the point. It isn’t searching files specifically, for these, it actually searches all of them at once. The whole thing. Having wp_head() anywhere at all will pass the check. Whether it is correct to have wp_head() where you have it is a whole different thing.

    If you don’t have wp_head() anywhere, then that’s what it is discovering. So, what file should be pointed to in that case? Theme-check has no idea of the structure of your theme. In a normal case, it should probably be in the header.php, but people structure things in unusual ways and your theme might not fit the normal mold.

    I can’t point you to a file for something not being there when I don’t know what file it should be located in with your own custom structure and layout.

    Understand that Theme Check cannot solve problems for you. It can only point out possible problems, in a non-specific and non-perfect way. It’s a first pass, designed to tell you about things you may have forgotten. I can tell you that you’re missing a wp_head call. I cannot tell you with any form of certainty whatsoever where you should put such a call. That depends on your theme, and for you to know the answer to that question, you need to know what wp_head does, and why you need it.

    Thread Starter Jesse Graupmann

    (@jgraup)

    I can’t point you to a file for something not being there when I don’t know what file it should be located in with your own custom structure and layout.

    True. And I’m not asking for recommendations on function call locations. Just as much info as you have when you make checks. I went through and noticed that you do glob a chunk of files so you’re telling me that it’s all of them at once – which helps me more than you would think.

    But I have a bunch of wp_head() calls… you know, this might be missing the “wp_head ()“. That same space bug.

    Ok, that was it. Don’t ask me why those functions were written with an extra space. I write C#, Swift, Objective-C, PHP, javascript and so on. I never add an extra space intentionally.

    But in my case, it looks like wp_head (), wp_footer (), wp_title () were all written with an extra space. You can see my frustration when a general rule is telling me it can’t find what I am clearly seeing.

    I’d still recommend line numbers for ‘sanitization callback function’ errors along with wp_title() and any other item where you already know the file and/or line number.

    I’m new to theme creation, I’m going to make mistakes but this plugin is doing a great job teaching me what to look for and where. So thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘REQUIRED: The tags can only contain a call to wp_title().’ is closed to new replies.