1. Add a new rewrite rule:
add_action('init', function()
{
add_rewrite_rule('^dog/([^/]+)/?$', 'index.php?cat=dog&name=$matches[1]', 'top');
}, 10, 0);
2. Filter the post link:
add_filter('post_link', function($post_link, $post, $leave_name = false, $sample = false)
{
if ( is_object_in_term($post->ID, 'category', 'DOG') ) {
$post_link = str_replace($post->ID . '-', '', $post_link);
}
return $post_link;
}, 10, 4);
Try it in your functions.php
. Hope it works for you!
Related Posts:
- Custom pages with plugin
- add_rewrite_rule, plugin activation and plugin deactivation
- Does flush_rewrite_rules() remove all rules added by other plugins as well as mine?
- Add_rewrite_rule doesn’t add custom url in plugin
- flush_rewrite_rules() not working on plugin activation
- Do rewrites added with add_rewrite_rule() persist after plugin deletion?
- WordPress rewrite rule depend on meta values not ids
- Custom pages with plugin
- Apache rewrite rules and wordpress problem
- Add Rewrite Rule for custom page
- What is the best way to output plugin result in certain url
- flush_rewrite_rules not working on plugin deactivation, invalid URLs not showing 404
- Custom rewrite rule is not picked by WordPress
- How can I rewrite a plugin generated URL?
- WordPress custom URL Rewrites redirecting not masking
- Best way to hook a custom url?
- Remove rewrite rules generated by plugin during deactivation
- How does WP handle multiple matching rewrite rules?
- How to Create a Custom Plugin Permalink
- Custom rewrite rules not working with WPML
- How to Create a Custom Slug for Tags and Categories with a prefix or suffix?
- Redirect to another page using contact form 7? [closed]
- Remove .htaccess portion upon plugin deactivation?
- Custom url rewriting
- URL rewrite with external JSON query
- WordPress rewrite rules not working
- How to rewrite URL and get the values?
- How to embed a new string in url?
- i want to rewrite my custom plugin url
- add_rewrite_rule to load different page, without changing URL in browser
- Change custom rewrite rule when permalink is updated/changed
- Change default url to plugin custom post type
- WP Job Manger change jobs url (NOT slug)
- Who are the most trusted plugin developers? [closed]
- Get plugin_dir_url() from one level deep within plugin
- Using add_filter inside another class
- SESSION in WordPress Plugin Development
- WordPress plugin installation error
- How long does it take for a new plugin to be approved?
- WordPress Plugin as ‘Library’ From Abstract Application?
- Good tools for locating hooks in a wordpress page/admin interface/blog post?
- Detecting when a custom taxonomy has been changed and display alert?
- Nested CPT URLs + Posts 2 Posts
- How can I get full attachment url from wp_get_attachment_metadata?
- Why is the Settings API is not saving my array of options
- Override comments.php template with plugin
- Custom plugins/Manipulated plugins: Always a terrible idea to inherit these types of WP sites that discourage updates? [closed]
- Accessing GET variable named ‘error’
- Demystifying and understanding shortcode nomenclature
- download_url() appears as grey icons
- How can I add an options page for my class based plugin?
- Sending WP posts to external API
- Issue with adding count to “subsubsub” aka quick links on custom_post_type
- Register Page Template from Plugin
- Private Plugin Updates – Localhost
- Any hook for pre-plugin-update -either bulk or single plugin update
- wp_create_nonce function doesn’t work inside a plugin?
- Making a plugin only available on the front-end for the logged in super admin
- When to load auto-login code?
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- Creating a Callback URL for WordPress Woocommerce to update Order Status
- How to replace WordPress Media Upload Window with user’s device window?
- How can i change the texts of plugin (created by me) in wordpress admin?
- URL rewrite of independent plugin?
- add_rewrite_rule behaving strangely
- WordPress : Explain Plugins & Theme string value in database
- modify plugin to support RTL
- Bulk update wordpress posts
- How to automatically add edit link on frontpage post of any wordpress theme?
- Plugin function inside custom plugin
- Is there a plugin for automatically adding a word or symbol after a trigger word? I.e. Like a search and replace but more like search and add? [closed]
- configuration of .htaccess for add_rewrite_rule to make sense
- How to use add_action for multiple instances of the same class
- Plugin option default value
- How can i listing current category and Featured Category post list?
- save_post_product action not firing
- How to get the custom field value using SQL query
- specific rows style for in custom list table using WP_List_Table
- How to add the search page link to the anchor tag?
- Has blocks gutenberg block multiples registers type in my Plugin
- Custom plugin settings page with tab. Error: “Sorry, you are not allowed to access this page.”
- return bbp_get_topic_author_id as integer
- I am Getting Sorry, no posts matched your criteria on form submit only for certain page [duplicate]
- Dynamic input fields in WordPress Plugin
- Custom role not listed
- Using meta_key & meta_value in add_rewrite_rule
- How to add a box note in wordpress plugin page ? top header side.
- WordPress Widget: Is it possible to make the form dynamic without updating?
- Why some plugins are including wp-includes/plugin.php file?
- Creating a user ‘add custom field’ section
- Creating custom URL for async content
- WordPress plugin options need to delete after deactivate & uninstall
- How can I pass value to function in add_menu_page?
- Making a Custom Post Type Publish Loop
- How to hide a piece of code from a wordpress web page?
- How to dispaly post informations (such as titles) in an admin plugin menu page?
- Someone Comment 1000 times in a Day in My WordPress Site, What Can i Do
- wp_enqueue_script doesn’t load JS in plugin
- AI Code For OpenAI
- Pulsing circle before the post title (Breaking news flash)