How to change ‘with_front” key from an existing custom post type?

I have a CPT called ‘experts’, that has been created in a theme I bought, and I can’t find out where nor where to change it.
I need to change a parameter to ‘with_front’ => false
Because my general permaling structure goes with /blog and I do’nt want experts to be in /blog/experts.
Is there a way I could do that adding something in the functions file?
I have tried this (How to set “with_front’=>false” to a plugin-generated cpt?) and various things, but could not get it to work.
Thanks 🙂

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

Method 2

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.

Method 3

This solution works, added to parent theme functions.php:

        add_filter( 'register_post_type_args', function( $args, $post_type )
        {
            $args['rewrite']['with_front'] = false;
            return $args;
        }, 10, 2 );


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x