Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Title check is not compatible with new title theme technique #10

Closed
NateWr opened this issue Nov 11, 2014 · 8 comments
Closed

Title check is not compatible with new title theme technique #10

NateWr opened this issue Nov 11, 2014 · 8 comments

Comments

@NateWr
Copy link

NateWr commented Nov 11, 2014

4.1 introduces a new title-tag theme feature. For backwards compatibility, the following is recommended:

if ( ! function_exists( '_wp_render_title_tag' ) ) :
function theme_slug_render_title() {
    echo '<title>' . wp_title( '|', false, 'right' ) . "</title>\n";
}
add_action( 'wp_head', 'theme_slug_render_title' );
endif;

This is throwing an error with the new title checks introduced in 9a6cbcb.

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

Using just wp_title() in the recommended code prints immediately, instead of returning for the echo statement. This can be worked around using ob_start(), or splitting into three separate statements, but this seems like a round-about way to pass the test. Should the check be updated to allow false for wp_title()'s second attribute?

@NateWr NateWr changed the title Title check is not compatible with new title them technique Title check is not compatible with new title theme technique Nov 11, 2014
@scottsousa
Copy link

@NateWr @Otto42

Here's what I've found:

This title regex check (https://github.com/Otto42/theme-check/blob/31a84b800ee709e247d4ec1e1eee59cf6849875a/checks/title.php#L45) seems to be the culprit.

Looks like the reason it's failing is because of the missing tags, the quotation marks, and the semi-colon after wp_title().

I'm sure Theme Check can eventually check for add_theme_support( 'title-tag' ) if necessary, or that function can be updated, or something else. If there's anything I can do to help, let me know. Just wanted to mention this.

For now, you could use the following to pass the check:

function theme_slug_render_title() {
?>
    <title><?php wp_title( '|', true, 'right' ); ?></title>
<?php
}

@Otto42
Copy link
Member

Otto42 commented Nov 25, 2014

A check for the add_theme_support is definitely something that needs to be added for this, along with shoring up the existing title check code.

@ScottSmith95
Copy link

This issue is preventing themes that support this feature from being submitted to the .org Theme Directory, FYI.

@Otto42
Copy link
Member

Otto42 commented Dec 16, 2014

This issue will be fixed when 4.1 is released. Themes should not support the new 4.1 features until 4.1 actually exists.

@Otto42
Copy link
Member

Otto42 commented Dec 16, 2014

Fixed in 0063b3b

@Otto42
Copy link
Member

Otto42 commented Dec 22, 2014

I've updated the backwards compat examples in the codex and in the original blog post to reflect the methodology used by _s, which will pass that particular part of theme-check.

Unfortunately, short of removing this particular check entirely, there's no way for it to recognize all possible ways to output a title tag. It looks for the most common way, which is to have <title> right in the header.php, and a <?php wp_title(); ?> inside it. Anything else inside title tags will cause that check to fail.

Theme-check does not run your code and look at the results, it's a simple scanner on the code itself. It isn't perfect, and it isn't going to be. Until we get a lot more title-tag adoption in themes, this check really needs to stick around as-is.

@ghost
Copy link

ghost commented Jun 12, 2017

@Otto42 Can you provide a link to the backwards compat example in the codex and blog post you mention please? I tried the above solutions but none of them works for me.

I think I am having issues with this using 4.8 and this being the last error, all other checks pass.
Despite turning off the check I would prefer to understand for example how TwentyFifteen manages to pass the check but my theme does not.

#191

@ghost
Copy link

ghost commented Jun 12, 2017

@Otto42 I found what it was! It was a, you will be laughing, <title> tag commented out in the HTML.
Once I deleted the commented <title> tag the check passed.
So this means the check scans for all instances of <title> regardless of if it is in a comment or not.
If you can still provide the links you mentioned I am interested to read that, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants