• Resolved skillbeatsall

    (@skillbeatsall)


    Hi!

    I have a custom post-type on my website that comes from a theme. The post type is named ‘gva_team’. In the URL, it looks like the following:

    [website]/teachers/firstname-lastname

    I want to replace teachers with “staff”. How would I go about doing this?

    Thanks ??

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • See if this works for you,

    1. Open your theme’s functions.php file or create a custom plugin file for this purpose.
    2. Add the following code to modify the rewrite rules for your custom post type:
    function modify_gva_team_rewrite_rules($args, $post_type)
    {
        if ($post_type === 'gva_team') {
            $args['rewrite']['slug'] = 'staff';
        }
        return $args;
    }
    add_filter('register_post_type_args', 'modify_gva_team_rewrite_rules', 10, 2);
    
    1. Save the changes to the functions.php file or your custom plugin file.
    2. After saving the changes, visit the WordPress admin area and navigate to “Settings” > “Permalinks.” Simply clicking the “Save Changes” button will flush the rewrite rules.

    This code uses the register_post_type_args filter to modify the rewrite parameter of the “gva_team” post type registration. It checks if the current post type is “gva_team” and updates the slug value to “staff”. This way, the base URL will be changed from /teachers/ to /staff/.

    Thread Starter skillbeatsall

    (@skillbeatsall)

    Perfect solution! Thanks, @abretado1985! ??

    Glad it worked!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Changing Post-type URL’ is closed to new replies.