Good day!
As the title says my custom function is not stopping after i do return.
I have created a child theme and create a function inside the functions.php file.
What i try to achieve is show the category title otherwise the string home as title.
What i end up getting now is both the category title and the string of home if i click on a category.
HTML:
<h3><?php echo header_title() ?> </h3>
PHP:
function header_title() {
if(single_cat_title() != NULL) {
return single_cat_title();
} else {
return 'home';
}
}
Anyone knows what went wrong here?
Any help will be appreciated here 🙂
single_cat_title
will only return a value if you set the second ($display
) argument tofalse
. Since you’re not specifying it, it’secho
ing the value, returning nothing, and you’re dropping through to yourelse
condition.Try providing that parameter (eg
if(single_cat_title('', false) != NULL) {
) in both your calls. Or store the result.