在我的主题中存在插件如何使用add_action(‘after_setup_theme’, ‘like_add_custom_post_types’)注册10个自定义帖子类型;我想更改它并仅注册2个。
我尝试使用remove_action()和新动作删除它, 但是有错误, 致命错误:无法重新声明like_add_custom_post_types()(以前在….(插件路径)中声明, //////此插件代码
function like_add_custom_post_types() {
$cpt = array(
'testimonials' => true, 'sliders' => true, 'sections' => true, 'events' => true, 'menu' => true, 'gallery' => true, 'team' => true, 'faq' => true, );
foreach ($cpt as $item => $enabled) {
$cpt_include = likeGetLocalPath( '/post_types/' . $item . '/' . $item . '.php' );
if ( $enabled AND file_exists( $cpt_include ) ) {
include_once $cpt_include;
}
}
}
add_action( 'after_setup_theme', 'like_add_custom_post_types' );
function like_rewrite_flush() {
like_add_custom_post_types();
flush_rewrite_rules();
}
///////// my code
add_action( 'after_setup_theme', 'remove_parent_theme_stuff', 0 );
function remove_parent_theme_stuff() {
remove_action( 'after_setup_theme', 'like_add_custom_post_types' );
}
add_action('after_setup_theme', "like_add_custom_post_types");
function like_add_custom_post_types() {
include_once ABSPATH.'/wp-content/plugins/like-themes-plugins/post_types/sections/sections.php';
}
add_action( 'after_setup_theme', 'like_add_custom_post_types' );
#1
搜索功能在主题中称为like_add_custom_post_types。给定错误, 主题为like_add_custom_post_types的函数已经存在。
怎么解决 :
- 将函数名称更改为其他名称。
如果要删除8个帖子类型, 请查找函数并注释register_post_type
add_action(‘after_setup_theme’, ‘like_add_custom_post_types’);
评论前必须登录!
注册