remove_action似乎无法正常工作

时间:2016-05-02 11:16:26

标签: wordpress woocommerce wordpress-theming storefront

我决定使用名为Galleria的Woocommerce Storefront子主题,当我以前使用了店面主题时,我使用了常见的remove_action取消了默认值并替换为我自己的add_action。

然而,由于Galleria是Storefront的子主题,它在文件class-galleria-structure.php中有自己的add_action,尽管add_action的结构看起来不同。

店面中的典型add_action看起来像这样......

add_action( 'storefront_header', 'storefront_site_branding', 20 );

我通常会使用以下内容在我的functions.php文件中取消挂钩...

remove_action( 'storefront_header', 'storefront_site_branding', 20 );

在Galleria子主题中,add_actions看起来像这样......

add_action( 'storefront_header', array( 'Galleria_Structure', 'galleria_top_bar_wrapper' ), 1 );
add_action( 'storefront_header', array( 'Galleria_Structure', 'galleria_top_bar_wrapper_close' ), 6 );

所以我假设通过执行以下操作,它只会解开它们......

remove_action( 'storefront_header', array( 'Galleria_Structure', 'galleria_top_bar_wrapper' ), 1 );
remove_action( 'storefront_header', array( 'Galleria_Structure', 'galleria_top_bar_wrapper_close' ), 6 );

在我的functions.php文件中尝试了这个,我发现它没有效果。

有人可以指出我正确的方向,因为我不知道为什么这不起作用。

全部谢谢

1 个答案:

答案 0 :(得分:0)

确保在add_action之后调用remove_action。还要检查函数是返回true还是false。

通常add_action挂钩在init或after_setup_theme上,所以只需尝试稍后执行的挂钩。

以下是运行顺序的所有挂钩的列表 http://rachievee.com/the-wordpress-hooks-firing-sequence/

相关问题