Custom function WordPress not stopping after return

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.

Read More

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 🙂

Related posts

1 comment

  1. single_cat_title will only return a value if you set the second ($display) argument to false. Since you’re not specifying it, it’s echoing the value, returning nothing, and you’re dropping through to your else condition.

    Try providing that parameter (eg if(single_cat_title('', false) != NULL) {) in both your calls. Or store the result.

Comments are closed.