我如何更改add_action('after_setup_theme','like_add_custom_post_types');这个钩子

时间:2019-02-08 07:23:14

标签: php wordpress wordpress-theming action

在我的主题中存在插件如何使用add_action('after_setup_theme','like_add_custom_post_types')注册10个自定义帖子类型;我想更改它并仅注册2。

我尝试使用remove_action()和writh新操作将其删除,但有错误,致命错误:无法重新声明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 个答案:

答案 0 :(得分:0)

主题中名为like_add_custom_post_types的搜索功能。由于出现错误,主题为名称like_add_custom_post_types的函数已经在主题中。

如何解决:

  • 将函数名称更改为其他名称。
  • 如果要删除8种帖子类型,请查找功能并评论register_post_type

    add_action('after_setup_theme','like_add_custom_post_types');