Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress WordPress Hooks - Actions and Filters Filter Functions in WordPress Real World Examples of WordPress Filters

Glenré Charl Labuschagné
Glenré Charl Labuschagné
23,204 Points

Zac sets a custom_wp_title() but never sets the $sep. Where does the "|" separator come from when the default is '»'?

So Zac set the $title and returns it, but never sets $sep. Where does the "|" separator come from? According to the WordPress Docs the default is '»'.

Glenré Charl Labuschagné
Glenré Charl Labuschagné
23,204 Points

O, it's set in the index.php… So because the $sep is not set it takes ('|', true, 'right')?

1 Answer

Glenré Charl Labuschagné
Glenré Charl Labuschagné
23,204 Points

So technically leaving the $sep unset in the function custom_wp_title() makes it available to set in the index.php with

<title><?php wp_title( '|', true, 'right' ); ?></title>.

And setting it $sep in the function custom_wp_title() overrides the manual set in index.php.

<?php 
function custom_wp_title( $title, $sep ) {
global $page;
// Add the site name.
$title .= get_bloginfo( 'name' );
// Add the site description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) {
    $sep = '&#x2602;';
    $title = "$title $sep $site_description";
} 
    return $title;
} 
add_filter( 'wp_title', 'custom_wp_title', 20, 2 );
// https://tommcfarlin.com/filter-wp-title/
?>