在Velux主题中functions.php
这是:
if ( is_front_page() && is_active_sidebar( \'hero\' ) )
这显然意味着英雄小部件只在主页上起作用。我使用该小部件添加了需要在所有页面的标题中的自定义HTML。我尝试了以下modfunctions.php
并清除了缓存,但无法在其他网站页面上查看自定义HTML。网站尚未公开。
if ( is_page() && is_active_sidebar( \'hero\' ) )
在Velux主题中functions.php
这是:
if ( is_front_page() && is_active_sidebar( \'hero\' ) )
这显然意味着英雄小部件只在主页上起作用。我使用该小部件添加了需要在所有页面的标题中的自定义HTML。我尝试了以下modfunctions.php
并清除了缓存,但无法在其他网站页面上查看自定义HTML。网站尚未公开。
if ( is_page() && is_active_sidebar( \'hero\' ) )
is_active_sidebar()
不引用特定的小部件。这意味着侧边栏中是否有任何小部件。
根据codex:
任何包含小部件的侧栏都将返回TRUE,而任何不包含任何小部件的侧栏都将返回FALSE。
而且is_page()
仅在运行查询时有效。在那之前,它在任何时候都不起作用,你可能也想看看。但是,由于您正在使用is_front_page()
我假设查询已经运行过了。
以下是GitHub上一位开发人员的成功答案。我把它放在我的函数中。php。
/**
* Ensure the hero widget persists across all pages
* @author GoDaddy
*/
function godaddy_persistent_hero() {
if ( is_front_page() || ! is_active_sidebar( \'hero\' ) ) {
return;
}
add_action( \'primer_after_site_header_wrapper\', \'primer_add_hero\' );
add_action( \'primer_hero\', \'custom_velux_hero\', 20 );
}
add_action( \'wp\', \'godaddy_persistent_hero\' );
/**
* Render the hero.
* @return mixed Hero widget markup.
*/
function custom_velux_hero() {
dynamic_sidebar( \'hero\' );
}
我正在尝试将其添加到函数中。php。在我的另一个站点上的测试实验室中,它可以很好地添加测试信息。但在这个网站上,我试图把它添加到什么都没有发生的情况下。该网站正在使用最新的woocommerce运行一个建筑节俭主题。有什么想法吗?我基本上只是想在每个产品页面上添加一行类似于免责声明但无法添加的文本。add_action(\'woocommerce_before_add_to_cart_form\',\'print_something_below_short_description\');