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

[New sniff?] No calls to wp_title() #97

Open
3 tasks
jrfnl opened this issue Dec 18, 2016 · 6 comments
Open
3 tasks

[New sniff?] No calls to wp_title() #97

jrfnl opened this issue Dec 18, 2016 · 6 comments

Comments

@jrfnl
Copy link
Contributor

jrfnl commented Dec 18, 2016

Rule type:

Error

Rule:

Check that there are no calls to wp_title()

Avoid hard coding to modify content. Instead, use function parameters, filters and action hooks where appropriate. For example wp_title should be modified using a filter.

Ref: https://make.wordpress.org/themes/handbook/review/required/#core-functionality-and-features

Theme check file covering this rule:

https://github.com/WordPress/theme-check/blob/master/checks/title.php

Notes for implementation:
  • This function can possibly be added to one of the discouraged/forbidden function sniffs and might not need a sniff to itself.
  • Beware that there is also a filter called wp_title. This sniff should not confused the filter with a function call.

To do:

  • Clarify the rule in the Theme Review handbook.
  • Create unit tests (and possibly add them to existing file if the sniff will be added to an existing functions sniff)
  • Create new sniff or adjust existing one
@grappler
Copy link
Member

The simplest way would be to add it as a restricted function as part of #9

@joyously
Copy link

If a theme can't use the wp_title function, why have the function?
I found it very useful for the h1 heading on archive pages or in index.php.

@grappler
Copy link
Member

grappler commented Dec 18, 2016

@joyously You should be using add_theme_support( 'title-tag' ); or the_archive_title` instead.

why have the function?

Like everything it was introduced when there was a need and now we have found a better way to solve the problem.

The function was nearly deprecated in WP 4.4 and so that chances are high it will be deprecated in the future.
https://make.wordpress.org/core/2015/10/20/document-title-in-4-4/

@joyously
Copy link

joyously commented Dec 19, 2016

@grappler

You should be using add_theme_support( 'title-tag' ); or the_archive_title instead.

The h1 heading is not handled by the title-tag theme_support and the_archive_title doesn't have all the same filters on it as wp_title.

@grappler
Copy link
Member

the_archive_title doesn't have all the same filters on it as wp_title.

You can always use the filter get_the_archive_title to make changes. wp_title() should only be used to add the title in the head tags.

@joyously
Copy link

You can always use the filter get_the_archive_title to make changes.

That's not the point. There could be plugins and child themes that are filtering wp_title and not the_archive_title. The theme should be able to call the wp_title function if it wants to.

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

No branches or pull requests

4 participants