How to hide page title from WooCommerce Storefront theme homepage?

我怕爱的太早我们不能终老 提交于 2019-12-22 14:06:32

问题


I am trying to hide the Storefront page title on my homepage. This code hides it from all the side:

function sf_change_homepage_title( $args ) {
    remove_action( 'storefront_page', 'storefront_page_header', 10 );
}
add_action( 'init', 'sf_change_homepage_title' );

But I can't use is_front_page() because WordPress loads functions.php before the $wp_query object has been set up with the current page, as explained here.

I would prefer not using the plugin "Title Toggle for Storefront Theme".

Thank you.


回答1:


You didn't understand right the answer you linked to. You can't use is_front_page() right inside functions.php, but you can totally use it in a callback function.

The is_front_page() conditional is only available after the query is setup, which happens at init.

So this:

function sf_change_homepage_title( $args ) {
    if(is_front_page()) {
        remove_action( 'storefront_page', 'storefront_page_header', 10 );
    }
}
add_action( 'init', 'sf_change_homepage_title' );

Will work.




回答2:


The solution is to replace "init" with "wp":

add_action( 'wp', 'sf_change_homepage_title' );

Thanks.



来源:https://stackoverflow.com/questions/36696549/how-to-hide-page-title-from-woocommerce-storefront-theme-homepage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!