【问题标题】:How can i change add_action( 'after_setup_theme', 'like_add_custom_post_types' ); this hook如何更改 add_action('after_setup_theme', 'like_add_custom_post_types');这个钩子
【发布时间】:2019-02-08 07:23:13
【问题描述】:

在我的主题中存在插件如何使用 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' );

【问题讨论】:

    标签: php wordpress wordpress-theming action


    【解决方案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');

    【讨论】:

    • 你需要删除帖子类型是问题
    猜你喜欢
    • 2017-06-18
    • 2021-03-18
    • 1970-01-01
    • 1970-01-01
    • 2017-10-01
    • 1970-01-01
    • 2020-04-03
    • 1970-01-01
    • 2020-03-09
    相关资源
    最近更新 更多