添加子主题函数时,自定义帖子类型不起作用

时间:2016-02-22 作者:Ayaz Ali Shah

我正在尝试通过子主题注册帖子类型function.php 但它不起作用。但是,当我添加父项时,效果很好functions.php.

add_action( \'init\', \'testimonial\' );
if ( ! function_exists( \'testimonial\' ) ) :
function testimonial() {
    register_post_type( \'testimonial\',
        array(
            \'labels\' => array(
                \'name\' => \'Testimonial\',
                \'singular_name\' => \'Testimonial\',
                \'add_new\' => \'Add New\',
                \'add_new_item\' => \'Add New Testimonial\',
                \'edit\' => \'Edit\',
                \'edit_item\' => \'Edit Testimonial\',
                \'new_item\' => \'New Testimonial\',
                \'view\' => \'View\',
                \'view_item\' => \'View Testimonial\',
                \'search_items\' => \'Search Testimonial\',
                \'not_found\' => \'No Testimonial found\',
                \'not_found_in_trash\' => \'No Testimonial found in Trash\',
                \'parent\' => \'Parent Testimonial\'
            ),
            \'public\' => true,
            \'menu_position\' => 15,
            \'supports\' => array( \'title\', \'editor\', \'comments\', \'thumbnail\', \'custom-fields\' ),
            \'taxonomies\' => array( \'\' ),
            //\'menu_icon\' => \'T\',
            \'menu_icon\' => plugins_url().\'/images/testimonial.png\',
            \'has_archive\' => true
        )
    );
}
endif;
有谁能指导我吗?我可以通过子主题注册post\\u类型吗function.php ? 我会很感激的。谢谢

1 个回复
SO网友:Sheldon Alag

尝试检查您的功能。该函数可能存在于代码中的某个位置。如果找不到,请尝试删除if 语句,然后像这样直接添加函数

function testimonial() {
    register_post_type( \'testimonial\',
        array(
            \'labels\' => array(
                \'name\' => \'Testimonial\',
                \'singular_name\' => \'Testimonial\',
                \'add_new\' => \'Add New\',
                \'add_new_item\' => \'Add New Testimonial\',
                \'edit\' => \'Edit\',
                \'edit_item\' => \'Edit Testimonial\',
                \'new_item\' => \'New Testimonial\',
                \'view\' => \'View\',
                \'view_item\' => \'View Testimonial\',
                \'search_items\' => \'Search Testimonial\',
                \'not_found\' => \'No Testimonial found\',
                \'not_found_in_trash\' => \'No Testimonial found in Trash\',
                \'parent\' => \'Parent Testimonial\'
            ),
            \'public\' => true,
            \'menu_position\' => 15,
            \'supports\' => array( \'title\', \'editor\', \'comments\', \'thumbnail\', \'custom-fields\' ),
            \'taxonomies\' => array( \'\' ),
            //\'menu_icon\' => \'T\',
            \'menu_icon\' => plugins_url().\'/images/testimonial.png\',
            \'has_archive\' => true
        )
    );
}
add_action( \'init\', \'testimonial\' );

相关推荐

如何在Functions.php中链接style.css

我是WordPress的新手;我刚开始学习WordPress。我想把风格联系起来。函数中的css。php,但我无法解决这里可能存在的问题。谁能给我指出正确的方向吗?指数php<?php get_header(); ?> <?php if ( have_posts() ) { while ( have_posts() ) { the_post();