I would like to change the home_url for a custom post type that I have created.
The reason I would like to change the home_url is so that the site logo then links to a different URL when someone is viewing a custom post.
The custom post type is named ‘usa’, therefore I want to change the logo / home url to link to mysite.com/usa/
I have used the code below to achieve this, however I get errors because other links that make use of home_url, such as menu links, then have ‘usa’ appended to them, e.g mysite.com/usa/example-post/usa/
Does someone know a better implementation?
add_filter( 'home_url', 'custom_home_url' );
function custom_home_url( $url )
{
if( is_singular('us') )
return $url .'/usa';
else {
return $url;
}
}