0

I'm trying to change the portfolio slug of my site's URL (www.website/portfolio/neleman-cava/) to something else, i.e work

I know I can do this through some plugins, but I honestly don't want to load up my website with useless plugins.

Would someone be able to help me and point out where I have to make any changes in the the single-portfolio.php

<?php

get_header();

if (have_posts()) : the_post();

$show_title = comet_meta($post->ID, 'show_portfolio_title');
$style = (comet_meta($post->ID, 'portfolio_title_bg') != '') ? 'parallax' : 'grey' ;

$project_category  = '';
$cats = get_the_terms(get_the_id(), 'portfolio_category');
if($cats){
  foreach($cats as $cat) {
    $project_category  .= $cat->name . ', ';
  }
  $project_category = rtrim($project_category, ', ');
}
?>

<article id="<?php echo esc_html($post->post_name); ?>" class="page-single">
  <?php if (!empty($show_title) && $show_title != 'no'): ?>
  <section class="page-title <?php echo esc_attr($style); ?>">

Any thoughts? Thanks a mil!

  • Did you use a plugin to create the portfolio post type? – czerspalace Nov 29 '16 at 2:00
  • 1
    If you're registering the post type yourself, you can change $args['rewrite']['slug'] to work. If you aren't able to modify the call to register_post_type(), then you can filter the arguments as shown here: wordpress.stackexchange.com/questions/247328/… – Dave Romsey Nov 29 '16 at 2:10
3

You can use register_post_type_args to modify slug of any custom post type.

You need to change portfolio slug to work? Then code should be like this.

add_filter( 'register_post_type_args', 'change_slug_portfolio_to_work', 10, 2 );

function change_slug_portfolio_to_work( $args, $post_type ) {

    if ( $post_type == 'portfolio') {
        $args['rewrite']['slug'] = 'work';
    }

    return $args;
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.