Changing the name of Custom Post type from Portfolio to Photos

I want to change the Portfolio (custom post type) which comes packed with the theme, I want to change it to Photos with the help of a child theme, because any updates to the theme will spoil the edit. I’ve already created a Child theme. I’ve extracted the code from functions.php which registers Portfolio Custom Post type with taxonomy. I want to change it because the theme has some nice features and layout for portfolios.

Please help me change it.

Thanks in Advance

#-----------------------------------------------------------------#
# Create admin portfolio section
#-----------------------------------------------------------------# 
function portfolio_register() {  

     $portfolio_labels = array(
        'name' => __( 'Portfolio', 'taxonomy general name', NECTAR_THEME_NAME),
        'singular_name' => __( 'Portfolio Item', NECTAR_THEME_NAME),
        'search_items' =>  __( 'Search Portfolio Items', NECTAR_THEME_NAME),
        'all_items' => __( 'Portfolio', NECTAR_THEME_NAME),
        'parent_item' => __( 'Parent Portfolio Item', NECTAR_THEME_NAME),
        'edit_item' => __( 'Edit Portfolio Item', NECTAR_THEME_NAME),
        'update_item' => __( 'Update Portfolio Item', NECTAR_THEME_NAME),
        'add_new_item' => __( 'Add New Portfolio Item', NECTAR_THEME_NAME)
     );

     global $options;
     $custom_slug = null;       

     if(!empty($options['portfolio_rewrite_slug'])) $custom_slug = $options['portfolio_rewrite_slug'];

     $portolfio_menu_icon = (floatval(get_bloginfo('version')) >= "3.8") ? 'dashicons-art' : NECTAR_FRAMEWORK_DIRECTORY . 'assets/img/icons/portfolio.png';

     $args = array(
            'labels' => $portfolio_labels,
            'rewrite' => array('slug' => $custom_slug,'with_front' => false),
            'singular_label' => __('Project', NECTAR_THEME_NAME),
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'hierarchical' => false,
            'menu_position' => 9,
            'menu_icon' => $portolfio_menu_icon,
            'supports' => array('title', 'editor', 'thumbnail', 'comments', 'revisions')  
       );  

    register_post_type( 'portfolio' , $args );  
}  
add_action('init', 'portfolio_register');

#-----------------------------------------------------------------#
# Add taxonomys attached to portfolio 
#-----------------------------------------------------------------# 


if (!function_exists('nectar_add_portfolio_taxonomies')) {

    function nectar_add_portfolio_taxonomies(){

        $category_labels = array(
            'name' => __( 'Project Categories', NECTAR_THEME_NAME),
            'singular_name' => __( 'Project Category', NECTAR_THEME_NAME),
            'search_items' =>  __( 'Search Project Categories', NECTAR_THEME_NAME),
            'all_items' => __( 'All Project Categories', NECTAR_THEME_NAME),
            'parent_item' => __( 'Parent Project Category', NECTAR_THEME_NAME),
            'edit_item' => __( 'Edit Project Category', NECTAR_THEME_NAME),
            'update_item' => __( 'Update Project Category', NECTAR_THEME_NAME),
            'add_new_item' => __( 'Add New Project Category', NECTAR_THEME_NAME),
            'menu_name' => __( 'Project Categories', NECTAR_THEME_NAME)
        );  

        register_taxonomy("project-type", 
                array("portfolio"), 
                array("hierarchical" => true, 
                        'labels' => $category_labels,
                        'show_ui' => true,
                        'query_var' => true,
                        'rewrite' => array( 'slug' => 'project-type' )
        ));

        $attributes_labels = array(
            'name' => __( 'Project Attributes', NECTAR_THEME_NAME),
            'singular_name' => __( 'Project Attribute', NECTAR_THEME_NAME),
            'search_items' =>  __( 'Search Project Attributes', NECTAR_THEME_NAME),
            'all_items' => __( 'All Project Attributes', NECTAR_THEME_NAME),
            'parent_item' => __( 'Parent Project Attribute', NECTAR_THEME_NAME),
            'edit_item' => __( 'Edit Project Attribute', NECTAR_THEME_NAME),
            'update_item' => __( 'Update Project Attribute', NECTAR_THEME_NAME),
            'add_new_item' => __( 'Add New Project Attribute', NECTAR_THEME_NAME),
            'new_item_name' => __( 'New Project Attribute', NECTAR_THEME_NAME),
            'menu_name' => __( 'Project Attributes', NECTAR_THEME_NAME)
        );  

        register_taxonomy('project-attributes',
            array('portfolio'),
            array('hierarchical' => true,
            'labels' => $attributes_labels,
            'show_ui' => true,
            'query_var' => true,
            'rewrite' => array( 'slug' => 'project-attributes' )
        ));

    }

}

nectar_add_portfolio_taxonomies();

Read more here: Changing the name of Custom Post type from Portfolio to Photos

Leave a Reply

Your email address will not be published. Required fields are marked *