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 trialGlenré Charl Labuschagné
23,204 PointsZac 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 '»'.
1 Answer
Glenré Charl Labuschagné
23,204 PointsSo 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 = '☂';
$title = "$title $sep $site_description";
}
return $title;
}
add_filter( 'wp_title', 'custom_wp_title', 20, 2 );
// https://tommcfarlin.com/filter-wp-title/
?>
Glenré Charl Labuschagné
23,204 PointsGlenré Charl Labuschagné
23,204 PointsO, it's set in the index.php… So because the $sep is not set it takes ('|', true, 'right')?