Genesis Portfolio Pro plugin is the simplest way to enable portfolio post type in Genesis. While the method is simple, we often want to edit the permalinks and slugs.
This tutorial provides the steps to change the labels and rewrite the portfolio page slug to your custom.
Change Portfolio to Project post type.
Add the following in functions.php
// Rewrite custom post type labels. add_action( 'init', 'rewrite_cpt_custom_labels' ); function rewrite_cpt_custom_labels() { // Return early if we don't have a portfolio CPT. if ( 'portfolio' === ! get_post_type() ) { return; } register_post_type( 'portfolio', array( 'labels' => array( 'name' => _x( 'Project Lists', 'post type general name' , 'genesis-Project-pro' ), 'singular_name' => _x( 'Project List' , 'post type singular name', 'genesis-Project-pro' ), 'menu_name' => _x( 'Project Lists', 'admin menu' , 'genesis-Project-pro' ), 'name_admin_bar' => _x( 'Project List' , 'add new on admin bar' , 'genesis-Project-pro' ), 'add_new' => _x( 'Add New' , 'Project List' , 'genesis-Project-pro' ), 'add_new_List' => __( 'Add New Project List' , 'genesis-Project-pro' ), 'new_List' => __( 'New Project List' , 'genesis-Project-pro' ), 'edit_List' => __( 'Edit Project List' , 'genesis-Project-pro' ), 'view_List' => __( 'View Project List' , 'genesis-Project-pro' ), 'all_Lists' => __( 'All Project Lists' , 'genesis-Project-pro' ), 'search_Lists' => __( 'Search Project Lists' , 'genesis-Project-pro' ), 'parent_List_colon' => __( 'Parent Project Lists:' , 'genesis-Project-pro' ), 'not_found' => __( 'No Project Lists found.' , 'genesis-Project-pro' ), 'not_found_in_trash' => __( 'No Project Lists found in Trash.' , 'genesis-Project-pro' ) ), 'has_archive' => true, 'hierarchical' => true, 'menu_icon' => 'dashicons-format-gallery', 'public' => true, 'rewrite' => array( 'slug' => _x( 'project', 'project slug' , 'genesis-Project-pro' ), 'with_front' => false ), 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions', 'page-attributes', 'genesis-seo', 'genesis-cpt-archives-settings' ), 'taxonomies' => array( 'project-type' ), ) ); }
Go to Settings → Permalinks and re-save permalink to flush your rewrite rules.
Change portfolio-type taxonomy to project-type.
Add the following in functions.php
// Rewrite custom post type Taxonomy labels. add_action( 'init', 'rewrite_cpt_tax_custom_labels' ); function rewrite_cpt_tax_custom_labels() { // Return early if we don't have a Project CPT. if ( 'portfolio' === ! get_post_type() ) { return; } register_taxonomy( 'portfolio-type', 'portfolio', array( 'labels' => array( 'name' => _x( 'Project Types', 'taxonomy general name' , 'genesis-Project-pro' ), 'singular_name' => _x( 'Project Type' , 'taxonomy singular name', 'genesis-Project-pro' ), 'search_items' => __( 'Search Project Types' , 'genesis-Project-pro' ), 'popular_items' => __( 'Popular Project Types' , 'genesis-Project-pro' ), 'all_items' => __( 'All Types' , 'genesis-Project-pro' ), 'edit_item' => __( 'Edit Project Type' , 'genesis-Project-pro' ), 'update_item' => __( 'Update Project Type' , 'genesis-Project-pro' ), 'add_new_item' => __( 'Add New Project Type' , 'genesis-Project-pro' ), 'new_item_name' => __( 'New Project Type Name' , 'genesis-Project-pro' ), 'separate_items_with_commas' => __( 'Separate Project Types with commas' , 'genesis-Project-pro' ), 'add_or_remove_items' => __( 'Add or remove Project Types' , 'genesis-Project-pro' ), 'choose_from_most_used' => __( 'Choose from the most used Project Types', 'genesis-Project-pro' ), 'not_found' => __( 'No Project Types found.' , 'genesis-Project-pro' ), 'menu_name' => __( 'Project Types' , 'genesis-Project-pro' ), 'parent_item' => null, 'parent_item_colon' => null, ), 'exclude_from_search' => true, 'has_archive' => true, 'hierarchical' => true, 'rewrite' => array( 'slug' => _x( 'project-type', 'project-type slug' , 'genesis-Project-pro' ), 'with_front' => false ), 'show_ui' => true, 'show_tagcloud' => false, ) ); }
Go to Settings → Permalinks and re-save permalink to flush your rewrite rules.
You can also check the custom post type and return early using this snippet.
// check if portfolio cpt exits. if not, abort. Return early. if ( ! post_type_exists('portfolio') ) { return; }
Change URL Slug for Portfolio Type
Nick Cernis posted a quick solution in WordPress Support to change the /portfolio/ slug and taxonomy /portfolio-type/ slug.
Here How you can do it.
STEP 1
Create a new folder under your/plugins/ folder called genesis-portfolio-pro-custom
STEP 2
Create a new file named plugin.php under the above folder we have created.
STEP 3
Open plugin.php we have created and add the following to rename slug on CPT single and CPT archive.
<?php /** * Plugin Name: Genesis Portfolio Pro Custom Slugs * Description: Alters Genesis Portfolio slugs. * Version: 0.1.0 */ namespace GPPCS; add_filter( 'register_post_type_args', 'GPPCS\portfolio_args', 10, 2 ); /** * Change Genesis Portfolio arguments. * * @param array $args Post type arguments. * @param string $post_type Current post type. * @return array Filtered post type arguments. */ function portfolio_args( $args, $post_type ) { if ( 'portfolio' === $post_type ) { $args['rewrite']['slug'] = 'project'; $args['has_archive'] = 'projects'; } return $args; }
Rename CPT single >> project and CPT archive >>projects to your own.
Add this too to change the taxonomy slug.
add_filter( 'register_taxonomy_args', 'GPPCS\portfolio_type_args', 10, 2 ); /** * Change Genesis Portfolio Type arguments. * * @param array $args Taxonomy arguments. * @param string $taxonomy Current taxonomy. * @return array New taxonomy arguments. */ function portfolio_type_args( $args, $taxonomy ) { if ( 'portfolio-type' === $taxonomy ) { $args['rewrite']['slug'] = 'project-type'; } return $args; }
Rename project-type to yours.
STEP 4
Activate the ‘Genesis Portfolio Pro Custom Slugs’ plugin.
Go to Settings → Permalinks and re-save permalink to flush your rewrite rules.