What are the different ways to detect home page in wordpress?

后端 未结 7 747
自闭症患者
自闭症患者 2021-02-06 04:59

What are the different ways to detect wordpress homepage

except is_front_page() and is_home()

Thanks

7条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-06 05:27

    In many situations a Wordpress site can have is_home and is_frontpage both eval as true on the REAL homepage and also on the main blog page. After building sites in Wordpress for about 4 years this still bothers me.

    For example if you have a site where you have your latest posts on your homepage with maybe a slider or some other homepage-centric elements, AND have another blog page, then is_frontpage and is_home will both eval as true on BOTH pages. So Wordpress does not have a clear conditional function for the true homepage, at least the way most people think of the homepage of a website.

    So I agree with Liam that if you get into a confusing situation, something like if ( $_SERVER["REQUEST_URI"] == '/' ) { }

    is more reliable.

提交回复
热议问题