从任何主题中删除 Woocommerce 侧边栏 [英] Remove Woocommerce sidebar from any theme
问题描述
我正在使用 WordPress 4.9.4,运行 27 个儿童主题主题和 Woocommerce 3.3.4 版.我正在尝试删除侧边栏......我尝试过使用:
I'm using WordPress 4.9.4 running Twenty Seventeen Child Theme theme with Woocommerce Version 3.3.4. I am trying to remove the sidebar… I have tried using this:
remove_action('woocommerce_sidebar','woocommerce_get_sidebar',10);
但还没有找到合适的.
如何删除所有侧边栏?
推荐答案
适用于所有主题的最好和最简单的方法是使用 get_sidebar
Wordpress action hook this方式:
The best and simple way that works with all themes is to use the get_sidebar
Wordpress action hook this way:
add_action( 'get_sidebar', 'remove_woocommerce_sidebar', 1, 1 );
function remove_woocommerce_sidebar( $name ){
if ( is_woocommerce() && empty( $name ) )
exit();
}
代码位于活动子主题(或活动主题)的 function.php 文件中.经过测试并有效.
您可能需要对一些与 html 相关的容器进行一些 CSS 更改
You might need to make some CSS changes on some html related containers
此代码适用于任何主题,因为所有主题都使用 get_sidebar()
Wordpress 函数作为侧边栏(甚至 Woocommerce 侧边栏)和 get_sidebar
操作钩子位于这个函数代码里面.
This code works on any theme as all themes use get_sidebar()
Wordpress function for sidebars (even for Woocommerce sidebar) and get_sidebar
action hook is located inside this function code.
这篇关于从任何主题中删除 Woocommerce 侧边栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!