I don’t understand why but the regex seemed to be the last issue. It was catching it but even with the post name hardcoded in it didn’t work correctly. This is the final working version.
add_filter( 'post_link', 'custom_permalink', 10, 3 );
add_filter('rewrite_rules_array','wp_insertMyRewriteRules');
add_filter('init','flushRules');
function custom_permalink( $permalink, $post, $leavename ) {
$category = get_the_category($post->ID);
if ( !empty($category) && $category[0]->cat_name == "Test" )
{
$permalink = trailingslashit( home_url('test/' . $post->post_name ) );
}
return $permalink;
}
function flushRules(){
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
function wp_insertMyRewriteRules($rules)
{
$newrules = array();
$newrules['^test/(.*)$'] = 'index.php?name=$matches[1]';
return $newrules + $rules;
}
Related Posts:
- How to change/rewrite the lost password url?
- How Can I Have A URL Changed Based on the Originating URL?
- Display Externally Retrieved Data within a Custom Template
- Custom permalink for attachment
- Change URLs in default WordPress slider to relative from absolute
- Change url to posts if they have custom tax only
- WordPress URL rewrite problem
- Not able to change wp_title using add_filter
- How to hook a filter to catch get_post_meta when alternate a custom field output?
- Changing JPEG compression depending on image size
- How to add headers to outgoing email?
- LESS CSS enqueue_style with add_filter to change rel attribute
- Remove Editor From Homepage
- Advanced Custom Fields and Yoast SEO keyword analysis [closed]
- Insert Custom HTML After Shortcode
- Is there a way to add another row to the tinyMCE kitchen sink toggle?
- Remove description from on Home
- add_filter to youtube embeds?
- How can I detect if a user changes their password?
- SSL certificate for the host could not be verified
- Store source permalink on XMLRPC calls
- How to limit the pages displayed for choosing parent page on page attribute’s menu?
- Moving sharedaddy buttons (in Jetpack) to the top of a post?
- WordPress RSS feed – filter RSS content by custom field value
- What is the filter hook for custom fields content?
- Filter keywords from search query
- Add class to woocommerce checkout body based on filter [closed]
- changing variable through filters or action hooks
- filter the_title problem in nav
- Changing Gutenberg / WP block editor width only on pages, not posts or other taxonomies
- How to replace any occurence of Gravatars with a local placeholder image?
- Sensei LMS Hooks to Remove Content
- Ignore dots when searching in the media library?
- How To Get User Data in Callback Function for pre_user_nicename?
- What’s the best way to split admin-only functionality in the theme’s functions.php file?
- Where is this inline CSS code [closed]
- When to use actions and when to use filters
- Which built-in WordPress files are safe to edit?
- Why won’t my preg_replace work with content_save_pre?
- How do I target a single page to modify the comment form of only that page?
- How Does comment_author Filter Work?
- Add ‘data-text’ attribute to TagCloud HTML
- Why in archive page doesn´t show read more button with excerpt?
- Removal of Jetpack OG Tags from old blog site
- Nesting if statements to echo only one string based on what tag was filtered?
- Contact Form 7 filter similar to preprocess_comment [closed]
- Walker_Nav_Menu doesn’t work in wp_page_menu_args filter
- get_posts() and filters
- Don’t see add_filter result in the site front page
- How to remove specific category from URL in WordPress
- upload_files cap to not loggen in users – add_cap to not logged in users
- Cannot change the definition of AUTOMATIC_UPDATER_DISABLED
- How do I add a checkmark to my-sites save settings hook
- How to customize the “Insert/edit link” popup box?
- How to filter backend post list showing only posts having a shortcode
- Add Lightbox To WordPress Native Gallery
- How do I override the_excerpt so that it will display full content?
- Get current user data
- get_post() containing gallery is outputting an unmatched closing div at the end of the content
- Trouble using remove_filter to override function in parent theme
- Load Posts’ individual body content on index starting at char 200 of each post
- How do I hook my function to run only after submitting login form
- Prepending character(s) to a custom tag title?
- How to write a filter to remove a form field (WordPress) [closed]
- Why doesn’t this function work when I know that the IP Address is “true”?
- Modify existing plugin function with add_filter
- include specific Pages to wp_list_pages with filter
- Map plugin with proximity search compatible with Buddypress
- How can I filter tag_description()?
- Create a pre-filtered version of the Media Library
- Which Filter Do I Use To Modify The Subject Of The Retrieve Password Notification Email?
- Register users by e-mail
- automatic title through filter
- Access posts while mod_rewrite is broken
- Filter causing loss of _wp_attachment_metadata
- Action hook to control access to certain parts of my site
- Buddypress Filter Multiple Activities [closed]
- How can I tranlslate post date in italian?
- Use alternative front page if cookie is set
- Having wp-admin on different domain
- Use a functions in functions.php to remove a string for template theme
- how to output HTML tags in post_content and not as plain text
- oembed_dataparse filter not running at all for standard YouTube embed
- Action for opening attachment or manipulating all attachment links
- Filter wp_mail based on content type
- Add filter conditionally to a page
- mu-plugins body_class filter not working
- shortcode function outputs multiple anchor tags
- WP Dashboard -> Posts-> Filter by Category -> Form Method Change : Which Hook
- Show child theme for users on specific IP
- Remove action added from class
- wp.getPosts with status = ‘trash’ using node.js
- Is there a way to overwrite a filter used in canonical.php?
- Adding an orderby filter, casting postmeta with multiple keys
- Identify admin/logout and more filters
- post->post_content filter
- How to create a list of terms who’s posts also have a predefined external term?
- Add rewrite endpoint and .htaccess
- How to change this WP logo and posts url in block editor?
- Add post id to url instead of WordPress default -2 suffix