• I am migrating a site and I want to have a custom taxonomy where I can input the old urls but the “/” cannot be parsed. This is my attempt:

    function wpse_56769_post_link( $permalink, $post ) {
    
        $default_term = 'previews';
        $terms = wp_get_post_terms( $post->ID, 'oldurl' );
        if ( ! empty( $terms ) && ! is_wp_error( $terms ) )
            $term = current( $terms )->slug;
        else
            $term = $default_term;
    
        $permalink = str_replace( '%oldurl%', $term, $permalink );
    
        return $permalink;
    }
    add_filter( 'post_link', 'wpse_56769_post_link', 10, 2 );
    
    function wpse_56769_rewrite_verbose_page_rules( $pass_through = NULL ) {
    
        $permastruct = $GLOBALS[ 'wp_rewrite' ]->permalink_structure;
        $permastruct = trim( $permastruct, 'herewehaveit/%' );
        if ( 0 !== strpos( $permastruct, 'oldurl%' ) )
            return $pass_through;
    
        $GLOBALS[ 'wp_rewrite' ]->use_verbose_page_rules = TRUE;
        return $pass_through;
    }
    add_filter( 'page_rewrite_rules', 'wpse_56769_rewrite_verbose_page_rules', PHP_INT_MAX );
    add_filter( 'do_parse_request',  'wpse_56769_rewrite_verbose_page_rules', PHP_INT_MAX );

    If I set the custom permalink to %oldurl% and the oldurl term for the post to something/123 it will link to something123 without the slash. Any solution to this?

  • The topic ‘Custom Permalink – Accepting “/”?’ is closed to new replies.