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)
- Trying to Find the PHP File/Function that Handles a Specific Form Action URL
- Uninstall, Activate, Deactivate a plugin: typical features & how-to
- Best way to initiate a class in a WP plugin?
- How do you debug plugins?
- How to structure a plugin
- What’s the preferred method of writing AJAX-enabled plugins?
- Add multiple plugin directories
- What are the differences between WPINC and ABSPATH?
- How to add a shortcode button to the TinyMCE editor?
- Where do I put the code snippets I found here or somewhere else on the web?
- What Plugins Demonstrate Great WP Plugin Development? [closed]
- is_plugin_active function doesn’t exist
- Delete WordPress plugin Repository
- How to change a user’s password programatically
- Who are the most trusted plugin developers? [closed]
- How can I find plugins’ slug?
- List all sidebar names?
- What are the common security flaws I need to look for? [closed]
- Get plugin_dir_url() from one level deep within plugin
- Pass PHP variable to javascript
- Where is the best place to use add_filter
- Can a developer adopt a plugin marked as “not updated in over 2 years”?
- Conditionally enqueue a widget’s script/stylesheet in HEAD (only when present on page!)
- How to implement WordPress plugin update that modifies the database?
- What is difference between get_bloginfo(‘url’) and get_site_url()?
- Custom media upload content for inserting custom post shortcode
- Stop a plugin in the activation process when a certain WP version is not met then show error message in admin_notices action hook
- How to Add a Third Level Sub Menu to the WordPress Admin Menu
- How to Add an Index to Plugin Database table
- Does the number of downloads displayed for a plug-in in the WordPress.org plug-in directory include automatic updates?
- how to create child WordPress plugin
- Redesigning Custom Post Type “Add New” page
- How to safely sanitize a textarea which takes full HTML input
- How to Remove Certain Screen Options and Meta Boxes from add/edit post type?
- Making my plugin multi-site compatible
- Why activate_plugin is not working in register_activation_hook
- Get plugin directory from a theme
- dealing with large HTML output via plugin code
- Best Practice for Referencing the Plugin Directory
- Getting Path To Uploaded Attachment Image After Upload
- Update plugin from personal API
- Giving Multiple Authors Access to a Plugin’s WP.org Repo
- Plugin upgrading: Widget settings
- Create a table in custom plugin on the activating it?
- How to call a plugin function from index.php
- dbDelta only creates the last table
- How would you require and automatically download dependent plugins?
- Update my custom WordPress Plugin through my own server [duplicate]
- Do plugin files have to follow a specific convention to be “picked up” by WordPress?
- Loading external page template and enqueue script from plugin causes 403 forbidden error
- How can I make it so the Add New Post page has Visibility set to Private by default?
- My custom made plugin has “a new version available” which links to unrelated plugin
- wp.media update options and force render on uploader
- WordPress Plugin Development In MVC Architecture, How?
- Creating two database tables via plugin
- Is it a good idea to edit an already existing plugin to add more functionality?
- How to stop showing admin notice after close button has been clicked
- Custom Filter in WordPress to modify footer information via plugin?
- Checking if an attribute exists in a shortcode
- How to create a WordPress plugin for another wordpress plugin?
- Does a plugin’s “main” file need to be named the same as the folder containing it?
- Query Posts by Custom Field ‘Price’
- Rewriting every url
- Is There a WordPress Hook to Filter the Edit Posts View?
- Symlinked plugin directory doesn’t appear in Admin
- Add section (add_settings_section) to a custom page (add_submenu_page)
- Where the Nickname is being used in WordPress