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?
- How do I make a redirect in PHP?
- How to include external page to wordpress page?
- Facebook Comment Count
- How to overwrite youtube embed?
- How to resize image on client-side before upload?
- Filter the blog title displayed in the header
- Foreach insert query the best way
- How to generate page content from database the right way?
- dynamic php inside wordpress page
- Converting MYSQL to WordPress $WPDB
- Get Admin Email Address From External PHP page
- Was told to change the .htacess file form .html to .php so this would work properly
- How to bypass maintenance mode with external cron?
- Displaying Woocommerce Product Category in WordPress
- PHP > Scheduled Tasks > Sending daily email with dynamic API variables
- How to make container class in PHP
- Insert page content into another page with a changed variable
- Decimal values via get_option() with custom local (decimal point = comma)
- Where can I find linked fonts in my theme?
- Undefined variable: row?
- How can I call a specific file (via php) by referencing the logged-in username?
- The additional fee for the COD payment method not visible in the front-end
- my_meta not saving in my current hosting
- Multilanguage website on two different domains
- Trying to display ads on only a third of posts in a loop. Keep getting Error 500?
- Convert ACF checkbox choices to links [closed]
- PHP – Multiple variables in insert post array