Here is something I came up with to solve this exact problem.
add_action('wp_list_categories','example_wp_list_categories');
function example_wp_list_categories($output) {
global $post;
foreach (get_categories() as $cat) {
if (preg_match("/\/category\/$cat->slug\//", $output)) {
$output = str_replace('/category/' . $cat->slug . "https://wordpress.stackexchange.com/", '/category/' . $cat->slug . '/?post_type=" . $post->post_type, $output);
}
}
return $output;
}
Regex isn”t a strong point of mine, so that might be improved upon.
Related Posts:
- What do ++ and *+ mean?
- Matching a space in regex
- How can I modify the permalink via a filter?
- Correct regex for wp_embed_register_handler
- sql query to put quotes around numbers in img tag
- Newbie question: no index.php? in my plain wordpress permalink
- Change links automatically to affiliate links
- Rewrite sub folder dynamically with country code in WordPress using PHP
- Use WordPress’ URL rewrite engine
- Wrap First Character after in a tag
- Rename “Portfolio” slug?
- How to rewrite URL with PHP variables with htaccess to a normal looking URL?
- Static variable and add_rewrite_rule?
- Nesting if statements to echo only one string based on what tag was filtered?
- How to change home or site url using action hooks or filter?
- Why do WordPress rewriites seem to work differently for posts vs pages?
- Performance impact of rewriting WordPress URLs
- Is sanitize_title_with_dashes formatting function too liberal (in terms of accepted characters)?
- Applying A Category to Existing Posts Where Page Title Matches Regex
- Changes in permalink structure in WordPress and how to apply to in-site links
- WordPress Persistent connection rule does not work for “posts”
- Append query string to all URL’s
- custom rewrite rule help! Custom rewrite rules not applying to custom post type
- subdirectory index.php is not working
- Use URL Rewrite as well as $_GET parameters in URL?
- How to modify URL (add GET values) after front end form submission?
- Extend PHP regex to cover “srcset” and “style” attributes
- parts of url disappear when using # inside href=”” [closed]
- Create custom permalinks to show Custom Post Type’s relationship?
- Add .htm extention to a custom taxonomy
- Help with .htaccess and Login with Subfolders
- how to remove colon and white space in a string by php
- Get URL from shortcode tag
- WordPress add_rewrite_rules for custom URLs ending in .html
- get_users meta_query: REGEXP not working for matching new lines
- Preg_Match(): compilation failed unknown property name
- Rewrite with pagination /foo/page/2/ to posts of a given category, page 2
- Divi change project category slug
- preg_replace regex problem
- How to add no follow to specific links?
- php preg_match with multiple patterns
- Extract links from content
- How to add a rewrite endpoint to unattached media?
- How do i add slugs to a URL, but still redirecting to the same page
- Nginx WordPress and another Web app URL structure
- Custom post type url Rewrite (conflicting with page url)
- WordPress Rewrite Rule
- Why is home page content not displaying with this rewrite rule?
- Modifying WP URL handing code?
- How to deal with a GET variable of ‘name’?
- Testing a Form’s Zipcode Field with Regular Expressions to Determine WordPress Page Behaviour
- How to define a rule in functions.php that ONLY disables the default wp functionality that undesirably changes ‘&’ to ‘#038;’?
- How to pass username in affiliate link in wordpress website
- Test the existence of a page/article by its URL, taking in consideration the URL rewriting by filters
- url not using query string no longer working
- Current WordPress Page Title as Search Parameter into A Tag
- How does one make a URL return dynamic JSON with custom Content Type?
- URL rewrite rule
- How does WordPress rewrite URLS using its PHP scripts
- WordPress add_rewrite_rule
- How can I turn a url with get method as a clean url with segment as the get method?
- RegExp to EXCLUDE strip HTML (FOR SOMME) comments
- WordPress Rewrite Issue
- How to print redirected query string variables to the page?
- Multiple URL from Custom post name
- Why isn’t my custom function kicking in from my functions.php file?
- Difference in Get Variable Location
- WordPress adding in site URL to header links
- How to strip/remove all blank spaces at the beginning/end of a search string
- WordPress add parameters with friendly url structure
- Custom taxonomy with page post type – WordPress
- Is there a way to get wp_editor (tinymce) content?
- How to cut a section of a URL from a string with a regular expression?
- Remove slug of multiple custom post types with and without hierarchical
- How to Dynamically Change the author_base URL Slug by Language in WordPress?
- WordPress add_rewrite_rule not working with page_on_front
- How to separate HTML and WordPress files
- WordPress Scripts Being Loaded in Footer
- Load wordpress content in other domain
- theme_root returning a truncated URI
- $wpdb->wp_users returning empty value for
- You do not have sufficient permissions to access this page while making a plugin
- WordPress Custom field Colors
- How to let users change site language?
- Search Query: how to construct a search string from two select elements?
- Problem with login form
- How do I get post attachments in menu_order in WordPress?
- How to change menu order item
- How to show only subcategories in parent category not parent category?
- Use of wp_insert_post and parameters
- Configure Php server with ISAP
- Genesis framework comments broken?
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- Best practice for show data to one specific user?
- Large Woocommerce Site (83,000 items), What Can I Do? [closed]
- How can I edit the content in index.php? [duplicate]
- Login to wordpress by clicking a link and specifying usernaname and password in url
- Irregular TTFB and server wait time response
- WordPress and Conditions
- Website needs to be opened for wp_mail to work