Customising the page title tag

Hi all,

I’m fairly new to Sage. I’m building a site which has a custom post type and I want to change the default <title></title> tag, but I can’t work out how to do it nicely.

The post type is for “vehicles”, I have a taxonomy for “make and model” and I’d like the selected taxonomy for each vehicle to be shown in the <title></title> tag instead of the default post title.

Can anyone point me in the right direction? Thanks

This is one of the things you would do with core WordPress filters.
The wp_title hook would be the place to look.

Whereas previously in Sage 9 there was a way to intercept the page title in the view controller Sage 10 uses WordPress’s wp_head() exclusively.

This is also true of the body_class, wp_body_open, and wp_footer. Which you can see in the index.php

Thanks, I did try using the wp_title hook but I couldn’t get it to work. I added a function to the functions.php — would that be what you’d do?

Explain “did not work” more.

Did you get undesired results, no results, or something else?

No results whatsoever, hence posting on here as it seemed like I must have been doing something wrong :slight_smile:

Sounds like that must be the correct route though afterall

Ah, looks like wp_title although still valid and used might not work. It was being deprecated long ago. Then wasn’t, and still exists, but doesn’t do anything? maybe… it should have worked.

Try the document_title_parts hook, which was the replacement and should be better… might even work well for your cases.

$title is an array, you can array_push those title parts on the end, or if you wanted to prefix the title array_unshift

1 Like

Thank you, I totally missed this hook. It works perfectly :slight_smile:

1 Like