remove woocommerce storefront homepage title php

℡╲_俬逩灬. 提交于 2019-12-24 10:04:14

问题


I am using storefront theme by woocommerce. I need to remove homepage title (h1) with php, i know css solution, but i don't want to use it, because i want to add h1 to other place in that page and it's bad for seo to have 2 h1's in one page! I also know about plugins that remove page title, but they are working as css display:none; property!

I tried all the snippets that i could find in web, but no luck!

Here is my site domain BrightBells.com

Here is PHP code snippets that i tried one by one by adding to my functions.php file, but none of its help!

Snippet 1

function wc_hide_page_title() {
if( is_front_page() ) 
    return true;
}
add_filter( 'woocommerce_show_page_title', 'wc_hide_page_title' );

Snippet 2

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

Snippet 3

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

Snippet 4

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

Snippet 5

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' );

Snippet 6

if ( is_front_page() ) {
remove_action( 'storefront_page', 'storefront_page_header' );
}

Snippet 7

if ( is_page('page id') )
{
  add_filter( 'the_title', '__return_false' );
}

None of this snippets help, please help!

Here is page settings screenshots! setting page screenshot

page screenshot Thanks in advance


回答1:


I hope you are using a child theme or plugin in doing this. Because it will just be removed when your theme updates.

In storefront version 2.2.5, it can be done with this code:

remove_action( 'storefront_homepage', 'storefront_homepage_header', 10 );

Update:
if on a child theme please do something like this:

if ( ! function_exists( 'storefront_homepage_header' ) ) {
    function storefront_homepage_header() { }
}

Child themes are run first before the parent theme. By doing so, we will define this storefront_homepage_header function first. In that case, the parent theme will not create it. Applicable only on themes that uses function_exists, luckily, storefront does.

remove_action will not work because the action has not been added yet.




回答2:


Try this ---

if ( is_front_page() || is_home() )
{
  add_filter( 'the_title', '__return_false' );
}


来源:https://stackoverflow.com/questions/46051486/remove-woocommerce-storefront-homepage-title-php

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