'Title-tag' is a theme feature introduced in Version 4.1, and I want to use it as the default title of my theme. This feature should be added on the after_setup_theme or init action. It is recommended here. The use of this feature works perfect for me. BUT:
Moreover, I have a custom titles function which can be enabled/disabled using the Option-Tree framework. This framework is loaded directly in functions.php. Then, I have the rest of the functions added on the after_setup_theme with priority 2:
add_action( 'after_setup_theme', 'theme_functions', 2);
And this is the filter added for my custom titles:
add_filter( 'wp_title', 'custom_titles', 10, 2 );
When I disable my custom_titles() function, the new feature title-tag works perfect, but when I enable the custom ones, it returns the title twice. Exactly that:
<title>Front page meta title example</title>
Front page meta title example<title></title>
The first one is correct, and it's using the wp_title() function inserted in the header.php between the title tags, but the second one it's included at the first line of the wp_head() function.
In fact, my custom_titles() function worked perfect without the use of the new feature title-tag. So it seems the conflict appears when I try to use both.
Do you think it'd be a good solution to put both features in after_theme_setup priority 1 in a simple conditional statement, or is there a better way for doing that? It seems the solution should be easier.
Aucun commentaire:
Enregistrer un commentaire