0

I am trying to add meta titles via the Yoast SEO plugin.

My theme is not compatible with this -- the resulting <title> tag is a concatenation of the Yoast title and the theme's title.

One solution is to ensure the <title> tag in header.php is set to <?php wp_title(''); ?> (see Yoast article here -- section "Themes without title-tag Support").

This method works (I tested it), and is also the solution suggested to me by my theme devs. But how can I do this via a custom function in my child theme's functions.php, rather than editing header.php?

I realize one possible solution is to copy header.php from parent theme to child theme, then edit that file. But I’m trying to avoid that if possible.

I tried the answer given in this previous question, but all that did was add a second <title> tag to the page, in addition to the existing, incorrect <title>.

1

If an incorrect <title> tag has been added to the header template the only option that will work is the child theme method. You can't override template markup with a custom function.

If you do use a child theme then don't use wp_title(), just remove the title tag entirely and register support for support title-tag.

  • Thanks for that. When you say, "You can't override template markup with a custom function," you are speaking in reference to the the <title> tag only--correct? Also, when you say, "If you do use a child theme then don't use wp_title(), just remove the title tag entirely and register support for support title-tag," that still requires me to edit header.php in my child theme--correct? – cag8f May 10 '18 at 13:22
  • "you are speaking in reference to the the <title> tag only--correct?" No. It's a general rule. You can change the outputs of functions that have a filter, or replace the template in a child theme, but you can't use a function to change arbitrary bits of markup within a template. "that still requires me to edit header.php in my child theme--correct?" Yes, to remove the title tag. – Jacob Peattie May 10 '18 at 14:11
  • "You can change the outputs of functions that have a filter" Got it. It was this that I just wanted to confirm was still possible. "you can't use a function to change arbitrary bits of markup within a template." Got it--that's what I'm trying to do here. I was hoping <title> was a special case, that perhaps had some special WordPress API function to arbitrarily modify it. Wishful thinking I guess. OK thanks for the explanation. – cag8f May 11 '18 at 4:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.