I've a theme with a plugin provided by theme developer for manage portfolios section. This plugin create a custom post type with this code:

// Portfolio post type
        'labels' => array(
            'name'          => __( 'Portfolios', 'Wyde' ),
            'singular_name' => __( 'Portfolio', 'Wyde' ),
            'add_new'       => __('Add New', 'Wyde' ),
            'add_new_item'  => __('Add New Portfolio', 'Wyde'),
            'edit_item'     => __('Edit Portfolio', 'Wyde'),
            'new_item'      => __('New Portfolio', 'Wyde'),
            'view_item'     => __('View Portfolios', 'Wyde'),
            'menu_name'     => __('Portfolios', 'Wyde')
        'public'      => true,
        'has_archive' => false,
        'rewrite'     => array(
            'slug'    => sanitize_title( $portfolio_slug ),
        'supports'   => array( 'title', 'editor', 'thumbnail'),
        'can_export' => true,
        'menu_icon'  => 'dashicons-portfolio'

I'd like to add the option with_front => false in rewrite, in order to put all the permalink in the root of my site. So I had to change the rewrite with:

'rewrite' => array(
    'slug' => sanitize_title( $portfolio_slug ),
    with_front => false,

I don't want to change the plugin file cause I will loose the change at every updates. Is it possible to add that option later, for example in function.php of my child theme?

Reading the register_post_type documentation it seems that is possible modify the post type (A function for creating or modifying a post type). I've tried to simply add this to my function.php:

        'rewrite' => array(
            'slug' => sanitize_title( $portfolio_slug ),
            with_front => false,

but it doesn't work.

I've tried also to redeclare all the params in register_post_type but it still doesn't work.

I've tried also with:

$no = get_post_type_object('wyde_portfolio');
$no -> rewrite['with_front'] = false;
register_post_type('wyde_portfolio', $no ); 

Do you have any suggestion on how I can solve it?

1 Answer 1


since WP 4.4.0, you can use this filter that allows you to change the arguments used in the original cpt registration.

Add this to your functions.php file:

add_filter( 'register_post_type_args', function( $args, $post_type ) {
    if( 'wyde_portfolio' === $post_type && is_array( $args ) )
        $args['rewrite']['with_front'] = false;

    return $args;
}, 99, 2 );

It's taken from a recent answer, https://wordpress.stackexchange.com/a/224376/39150

Hope it helps!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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