• sorry if this has been ask many times, but can’t find a workable solution.

    how to rewrite a custom slug /careers/ to /candidates/ when its hard coded into the theme without only override function

    This is the code i need to change:

    if( 'career' == $post_type ){
    			$slug = get_option('tommusrhodus_careers_slug', 'careers');
    			$home .= '<li class="active"><a href="' . esc_url( home_url( "/". $slug ."/" ) ) . '">' . esc_html__( 'Careers', 'stack' ) . '</a></li>';
    		}

    I have tried.

    function change_post_types_slug( $args, $post_type ) {
    
       /*item post type slug*/   
       if ( 'careers' === $post_type ) {
          $args['rewrite']['slug'] = 'candidates';
       }
    
       return $args;
    }
    add_filter( 'register_post_type_args', 'change_post_types_slug', 10, 2 );

    but this doesn’t work in the child theme functions.php even after resaving the permalinks.

    Any ideas?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Be sure the option value in your DB for “tommusrhodus_careers_slug” is “candidates” or that snippet will not generate the desired URL. What about the label ‘Careers’? If you want that changed without hacking the original code, use the “gettext” filter.

    Your post type args filter appears to be correct. You also need to visit the permalinks settings screen to cause WP to regenerate rewrite rules. No need to change anything, just load the screen in your browser.

Viewing 1 replies (of 1 total)
  • The topic ‘custom post slug rewrite’ is closed to new replies.