Wordpress - is_home()和is_front_page()不起作用

I have set everything, including set the front page to "Home" page in reading setting, here is the screenshot: enter image description here

And I added:

if( !is_home() && !is_front_page()) {
   echo "string";
}

But I still get "string" at the top of home page, as you can see in the screenshot.

Could anyone tells me why?

Thanks for any helps :-)

is_front_page() returns true if the user is on the page or page of posts that is set to the front page on Settings->Reading->Front page displays

So if you set about us as the front page then this conditional will only be true if showing the about us page.

is_home() return true when on the posts list page, This is usually the page that shows the latest 10 posts.

If the settings under Front page displays are left at default then the home page will return true for both is_front_page() and is_home()

An example of using is_home():

  • You have set your posts page to a page called News.
  • A user navigates there and in the header you want to show additional navigation
  • You could use is_home() to do this.

Example:

// Add below code in your functions.php
add_action('loop_start', 'Test_hook_check');
function Test_hook_check(){
    if( !is_front_page() ) {
        echo "string";
    }
}

You need to use is_front_page() for static pages.