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
- Make Current/Active Page Number a Link (WP_LINK_PAGES)
- How to show number of unpublished articles?
- How to retrieve the data from the sever and displaying it in a page?
- Javascript not loading on certain page
- Display WordPress Post on A Different Site
- Add row to custom database Table and delete all rows older than 1 day
- PHP: $_SESSION destroyed after page reload for my custom session
- Wp Query : Order by distance lat,lon
- Hide publish date when update date
- Category Page Displaying all Pages
- problem connecting to the administrator
- Looping through dummy posts and showing them in the main index.php
- Force Sidebar on Full Width page
- Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
- PHP – Woocommerce 3.2 Add variable shipping insurance with multiple “else if ” conditions
- Shortcode Works for Logged in Users but Not Working for Guest
- Fix mod_pagespeed Fetch timed out error on bitnami AWS wordpress installation
- Adding my own custom template page but got white page
- WordPress will suddenly stop saving files uploaded by my code (ran in nopriv ajax)
- Adding javascript files to WordPress and jQuery version
- Display default WordPress login/registration form into a modal window
- How do I use CSS or PHP to customize WordPress Form Manager Plugin Table?
- WP Login Button for current domain
- MySQL update text field with ‘
- WP_Query based on another query on the page
- One folder to be accessible by one user