WordPress Page Titles, Filters, and Child Themes

Themes are required to provide a wp_title() filter. If you’re making a child theme, you can’t remove that filter in your functions.php because the child theme loads before the parent. So here’s how you override the parent theme’s wp_title() filter. Assuming parent_wp_title() is the name of the parent theme’s filter:

/* declare your wp_title() filter */
function mytheme_wp_title($title, $sep) {
   ...your filter code here...

/* tell WordPress to remove the old filter, add the new one... but later. */
function adjust_wp_title_filters() {
	remove_filter( 'wp_title', 'parent_wp_title', 10, 2 );
	add_filter( 'wp_title', 'mytheme_wp_title', 10, 2 );

Stick that in your functions.php, and you should be good to go

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s