在wordpress中从init中删除一个动作(Remove an action from init in wordpress)
我有一个主题定义了一个新的帖子类型,但我想在子主题中删除该功能:
父母主题功能:
add_action('init', 'portfolio_register'); function portfolio_register() { //post type definition }儿童主题功能:这是我试过的,但它不起作用。
function child_remove_parent_function() { remove_action( 'init', 'portfolio_register' ); } add_action( 'init', 'child_remove_parent_function', 15 );任何人都知道我做错了什么? 提前致谢。
I have a theme that defines a new post type but I want to remove that function in the child theme:
PARENT THEME FUNCTION:
add_action('init', 'portfolio_register'); function portfolio_register() { //post type definition }CHILD THEME FUNCTION: This is what I tried but it is not working.
function child_remove_parent_function() { remove_action( 'init', 'portfolio_register' ); } add_action( 'init', 'child_remove_parent_function', 15 );Anyone has an idea of what am I doing wrong? Thanks in advance.
最满意答案
在子主题function.php中添加操作之前尝试此代码
<?php remove_action( 'init', 'portfolio_register' ); ?>要么
<?php add_action( 'after_setup_theme','remove_portfolio', 100 ); function remove_portfolio() { remove_action( 'init', 'portfolio_register'); } ?>try this code before add action in child theme function.php
<?php remove_action( 'init', 'portfolio_register' ); ?>or
<?php add_action( 'after_setup_theme','remove_portfolio', 100 ); function remove_portfolio() { remove_action( 'init', 'portfolio_register'); } ?>更多推荐
发布评论