WordPress页脚小部件未在我的子主题中显示。

huangapple go评论77阅读模式
英文:

WordPress footer widgets are not displaying in my child theme

问题

我正在使用Woocommerce为WordPress构建电子商务商店,使用Storefront主题。我创建了一个子主题来移除默认的侧边栏,然而这也导致页脚小部件区域中的小部件不显示。如果我切换回父主题,它们就可以正常工作。

这是子主题的functions.php:

<?php
function mb_remove_sidebar() {
    return false;
}

add_filter( 'is_active_sidebar', 'mb_remove_sidebar', 10, 2 );

如何恢复页脚小部件?

英文:

I'm building an ecommerce store with Woocommerce for WordPress using the Storefront theme. I created a child theme to remove the default sidebar, however this also has the side effect that widgets in the footer widget areas are not displayed. If I switch back to the parent theme, they work just fine.

This is the functions.php of the child theme:

&lt;?php
function mb_remove_sidebar() {
    return false;
}

add_filter( &#39;is_active_sidebar&#39;, &#39;mb_remove_sidebar&#39;, 10, 2 );

How can I get the footer widgets back?

答案1

得分: 1

您的代码正在移除所有侧边栏。请注意您想要移除的侧边栏ID,然后注销特定的侧边栏。

add_action( 'widgets_init', function() {
    unregister_sidebar( '您的侧边栏ID' );
}, 11 );

更多信息请参考 https://codex.wordpress.org/Function_Reference/unregister_sidebar

英文:

Your code is removing all sidebars. Note the sidebar ID you want to remove and then unregister the specific sidebar.

add_action( &#39;widgets_init&#39;, function() {
    unregister_sidebar( &#39;your-sidebar-id&#39; );
}, 11 );

For more information see https://codex.wordpress.org/Function_Reference/unregister_sidebar

答案2

得分: 0

以下是我认为的最佳方式,应该在你的子主题中创建自己的 sidebar.php 文件,以覆盖父主题并在这里编辑代码,而不是在你的函数内部。

以下是默认文件,你可以简单地在 if 语句中删除感叹号。

&lt;?php
/**
 * The sidebar containing the main widget area.
 *
 * @package storefront
 */
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
	return;
}
?&gt;

&lt;div id="secondary" class="widget-area" role="complementary"&gt;
	&lt;?php dynamic_sidebar( 'sidebar-1' ); ?&gt;
&lt;/div&gt;&lt;!-- #secondary --&gt;
英文:

The best way to do this in my opinion would be to create your own sidebar.php file in your child them to overwrite the parent and edit the code here instead of within your functions.

Below is the default file, you can simply remove the exclamation mark in the if statement.

&lt;?php
/**
 * The sidebar containing the main widget area.
 *
 * @package storefront
 */
if ( ! is_active_sidebar( &#39;sidebar-1&#39; ) ) {
	return;
}
?&gt;

&lt;div id=&quot;secondary&quot; class=&quot;widget-area&quot; role=&quot;complementary&quot;&gt;
	&lt;?php dynamic_sidebar( &#39;sidebar-1&#39; ); ?&gt;
&lt;/div&gt;&lt;!-- #secondary --&gt;

huangapple
  • 本文由 发表于 2020年1月3日 18:33:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/59577003.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定