I suspect the extra slash is coming from the str_replace action because normally there’s no need to manually add slashes when retrieving TAX urls.
Since you now end up with 1 unwanted slash, I would recommend testing situations with/without the slash. Starting with removing the one in the function definition. Make it empty, see what happens.
That is the first step to look into, in my opinion. I think this post might help you a bit as well: https://codex.wordpress.org/Debugging_in_WordPress
Related Posts:
- Rewriting a custom-post-type permalink with taxonomy term?
- Custom Post Type Permalink / Rewrite not working immediately
- Permalink Structure for Multiple Post Type Archives by Taxonomy
- Remove slug in taxonomy url
- Taxonomy, Terms, and Template Files
- custom post type and custom taxonomy permalink
- Is there a way to use regular categories with custom post types?
- Templates for Custom Post Types and Custom Taxonomies
- Dynamic taxonomy in permalink made all other posts NOT FOUND?
- Create permalink structure for one taxonomy archive per custom post type
- Custom Post Type Permalink For Parent/Child, 404 Page Not Found Error
- Custom permalinks
- Understanding Permalinks on Custom Post Types
- Add links to post categories and taxonomies in wysiwyg link modal?
- Rewrite permalinks for custom posttype and custom taxonomy
- How to check if last uri segment is a custom post type or taxonomy term?
- Custom Permalinks for Custom Post Types and Taxonomies
- Custom taxonomy & post slug permalink
- Including two taxonomies in a permalink structure
- WP Rewrite Rules – Custom post type & taxonomy
- Remove base slug in CPT & CT, use CT in permalink
- Maintaining WP_Query Relation Among CPT, Custom Taxonomy, Permalinks- CPT UI
- Custom post type category, taxonomy and URL rewrite problem
- Define permalinks for custom post type by taxonomy in WP 3.4
- Permalink Structure problem with cpt and custom taxonomy
- Custom Taxonomy List links being re-written
- Remove taxonomy slug when not assigning taxonomy with custom post types
- Custom Post Type: How to display all of same taxonomy?
- Custom Post Types, Custom Taxonomies and Permalinks ?
- Custom post type permalinks giving 404s
- Custom Taxonomies: Multiple Hierarchical Permailnks For A Single Post + Prev/Next Links
- Remove “-2” from a Toolset Types URL with the same post name
- Add the .html extension to custom post types
- What is better: Custom Fields vs Custom Taxonomies with Terms for perfomance, scalability and better user experience
- Custom Permalink Tag breaks Pagination
- Custom Permalink with Dynamic Taxonomy for Custom Post Type – Works, but breaks other permalinks
- Custom Permalink for Taxonimie and Custom Post Type
- Programmatically adding posts
- How to create a permalink structure with custom taxonomies and custom post types like base-name/parent-tax/child-tax/custom-post-type-name
- removing custom tax & CPT slug, adding taxonomy term in front of custom type
- multiple url slug for single custom post type
- Custom post type and taxonomy permalinks – Structure
- Custom Post Type and Custom Taxonomy Permalinks
- Custom post types, taxonomies, and permalinks
- Custom Post Type with two hierarchical Custom Taxonomies: strategy to generate best permalink structure
- How to specify URLS for custom posts & taxonomies
- Permalinks not working for custom taxonomy on custom post type
- Permalink Structure CPT With Custom Taxonomy Fails
- Change Permalink Structure for Tag.php template
- Custom Post Type permalink shows wrong page: homepage/index.php
- Custom post type url with category
- Adding custom post category slug in permalink causes 404 error for pages and posts
- Removing custom post type slug from URL
- Customize Custom Post Type URL
- How to have this permalink structure: post_type/postname/custom_inner_page
- Custom taxonomy returns 404
- CPT’s with landing page instead of archive – Url Rewrite?
- Permalink structure with custom taxonomies and custom post type like /parent-tax/child-tax/custom-post-type-name (with no base name)
- permalink /category/post-name with custom post type and taxonomy
- Custom post type and taxonomy permalinks
- Hierarchical permalinks for custom post type and taxonomy
- Custom post type Permalinks with hierarchical Taxonomies
- Best way to specify “article type” in URL
- Template files for Custom Post Type and Taxonomy
- Can’t use pagination with custom taxonomy
- Template for custom post type when taxonomy is in the URL
- How to filter a custom post type by custom taxonomy without 404
- Using page title as a link to term archive
- Is it possible to have hierarchical taxonomy and hierarchical custom post types in one permalink?
- Custom category URL not displaying posts
- Multiple permalinks for a single post with multiple taxonomies
- Duplicate slug/permalink issue while adding same post name
- Error 404 change permalink term custom term taxonomy
- How do you create pillar content pages?
- Custom post type single page returning 404 error when sharing archive url with custom taxonomy
- Permalinks: custom post type -> custom taxonomy -> custom sub taxonomy -> post
- Pretty Permalinks with CTP and Taxonomies / Hierarchical
- Customise Permalink Structure For Custom Post Types
- % encoded URL giving 404 error in WordPress
- Issue with Custom Post Types and Permalinks
- Custom post type URL structure with site.com/custom_taxonomy_slug/post_name
- Pretty permalink structure with multiple (AND OR) taxonomies
- How to have permalink structure based on taxonomy terms
- Multiple post types or single post type with category taxonomy?
- Custom Post type and Taxonomy in post URL error
- How can I add a “fake” parent into the permalink?
- How to retrieve the permalink for a specific (custom) term?
- Remove Custom Taxonomy Slug only without removing Custom post type slug in permalinks
- Adding 2 CPT with multiple custom taxonomies to permalinks
- WordPress Custom Permalink Structure with Custom Post Type and Taxonomies
- Add taxonomy to custom post type archive
- Permalinks Works for Custompost type but not with pages Why?
- Problem with Custom Post Types, Taxonomy, permalink, Archive
- Permalink for Custom Post Types
- 404 Error On Custom Taxonomy Pages 2, 3, etc
- Two Permalinks with one Taxonomy (custom taxonomy) and (custom post type -> custom taxonomy)
- Modify permalink of CPT archive to support two taxonomies
- Have Custom Taxonomy Slug Fall Under Custom Post Type Slug
- Custom Post Types Do Not work on this permalink setting https://somedominaname.com/%category%/%postname%/
- How to get the proper category in permalink with custom post type assigned to multiple categories