WPTT / WPThemeReview

PHP_CodeSniffer rules (sniffs) to enforce WordPress theme review coding conventions
MIT License
209 stars 37 forks source link

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

Open jrfnl opened 7 years ago

jrfnl commented 7 years ago

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:

To do:

grappler commented 7 years ago

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

joyously commented 7 years ago

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 commented 7 years ago

@joyously You should be using add_theme_support( 'title-tag' ); orthe_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 commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

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.