Wordpress - How to change 'with_front" key from an existing custom post type?

You could try the newly register_post_type_args filter to adjust it.

Here's an untested example:

/**
 * Set 'with_front' to false for the 'experts' post type.
 */
add_filter( 'register_post_type_args', function( $args, $post_type )
{
    if( 'teachers' === $post_type && is_array( $args ) )
            $args['rewrite']['with_front'] = false;

    return $args;
}, 99, 2 );

Updated with new info from @Agnes: the post type is teachers not experts.


Additionally, if the CPT has taxonomies associated with it, I've successfully used the following code to rewrite those as well:

/**
 * Set 'with_front' to false for the 'portfolio_category' post taxonomy.
 */

add_filter( 'register_taxonomy_args', function( $args, $taxonomy )
    {
        if( 'portfolio_category' === $taxonomy && is_array( $args ) )
            $args['rewrite']['with_front'] = false;
        return $args;
    }, 99, 2 );

In case that is helpful to anyone.

Tags:

Permalinks