You should use flush_rewrite_rules
function for that.
You have to remember, that this is expensive task, so you should not do it every time the site loads (many tutorials are making such mistake).
Of course you can use it in your plugin activation hook:
register_activation_hook( __FILE__, 'myplugin_flush_rewrites' );
function myplugin_flush_rewrites() {
// call your rewrite rules registration function here (it should also be hooked into 'init')
myplugin_custom_rewrite_rules_registration();
flush_rewrite_rules();
}
Related Posts:
- permalinks with get variables
- WordPress plugin how to run function when button is clicked
- Use an empty page to build custom plugin output
- Add Post and Comments menu no longer visible
- Creating a path in a plugin to call a function
- URL rewriting must be activated manually for my plugin
- 404 errors after plugin options update and category base change
- Support auto-save and revisions for custom fields
- Why doesn’t flush_rewrite_rules run on plugin activation?
- Help With Rewrite_Rules For a Custom Plug-In
- Append varible to url or set session
- How can I turn a custom wordpress page into a product page?
- rewrite URL based on selected taxonomy for post page
- Problem with dinamic add_rewrite_rule()
- Remove custom post type slug from URL and add taxonomy Slug
- add_rewrite_rule behaving strangely
- custom permalink’s rewrite rule for page id
- WordPress publish_post hook not getting featured image and meta on first publish, but works on updating title
- Show content without a post
- How to get post image root URL?
- How to create new content type and flushes rewrite rules without visiting the permalinks page?
- Forward an old url rewrite scheme to a new one?
- Changing permalink structure breaks link to .php file which generates files dynamically
- wp_insert_post generated mixed permalinks
- How to link to custom “archive like” page with custom permalink rules “dynamically”
- Add variables from rewrite rules to query var
- Home page is not loading, where in other pages are displaying on the site
- Get the current post/page URL with plain permalinks
- Adding body class in author page for custom role
- Author Meta in Author URL Link
- WordPress plugin how to run function when button is clicked
- Get (eventual) permalink from post within Edit Post in Admin panel
- WordPress permalink setting
- Get URL of Post You Are Editing
- How to use permalink query to go to specific tabs in posts
- Custom rewrite, url path with parameters to a page
- What is the difference between $post_id and get_the_ID()?
- How can I add columns to the post edit listing to show my custom post data?
- Custom frontend page for plugin without a ‘physical’ page?
- Using AJAX in a plugin to submit form – REALLY confused
- Plugin Architecture/Design Pattern – is better to use a private Observer/Mediator Pattern for plugin subclasses or WP add_action?
- Having Problem On Getting WP Post Gallery Images URL
- Post added via wp_insert_post with category doesn’t show in category listing
- How to add more than 1 user role to sub-menu pages
- How to properly use a hook to create template for custom product type in a plugin such as Woocommerce? [closed]
- Using a front controller in a WordPress plugin, any suggestions?
- How do I determine if a category exists by ID?
- How to load the plugin only when logged in?
- Self-hosted plugin update problems
- How to avoid creating first submenu page that is same as menu page?
- Hook into theme-switching later than `setup_theme`
- Save image as featured image
- Best choice of options/settings framework for plugin/theme development
- Hide plugin dashboard menu item for specific roles
- How to use relative path with my plugins folders?
- Files automatically added
- Upload to a remote server using wp_remote_post
- Is it possible to change a term slug before being saved to the database?
- How To Change Logout Screen Title
- onclick post title in admin area javascript file not working
- How can I edit commit messages in my wp-hosted plugin repo?
- How to integrate CLEditor to comment system?
- Adding dropdown list to tutor lms registration form
- Admin – Handle data before creating or updating a post, page or custom post
- How to Bind one post object Type with other postobject Type in Advanced Custom field [closed]
- wp_redirect on base wp-admin and login
- As a plugin developer, how do I remove a plugin from the global plugin directory? [duplicate]
- Creating custom input fields on the admin side
- What to hook into to check a value before a post is published?
- How to add a gradient component to a custom block
- Can’t get AJAX call working in custom plugin
- How leave selected checkboxes marked after they are selected and saved in the database
- Custom avatars in wordpress comments?
- How to create custom dynamic url
- Any way to update_post_meta with html content? It gets stripped and becomes empty
- How to get the number of pages when paginating comments?
- Getting posts by taxonomy
- can members have multiple registration using the same password?
- Exclude Woocommerce Product Category From Sitemap
- WordPress (pagenow link) in ajaxurl change after i change plugin language
- How to show only the last two categories in a menu?
- Get API auth_token token to renew weekly
- User meta query using Wildcard
- use a (Polymer) web component within a plugin (or theme)?
- how to add security questions on wp-registration page and validate it
- Hiding WordPress REST endpoints from public viewing using Basic Authentication
- Customize WordPress Admin Menu
- Dedicated server and WPDB Class : huge slow-down of the website
- Add Button to TinyMCE Custom Menu
- How should I use wpdb class to submit a form in admin dashboard?
- Rewriting URLs with a query string
- Forcing ALL plugin Admin menus into a separate menu
- Looking for Hook that is fired after a plugin or wp upgrade is installed/updated
- Woocommerce: block user removing cart item
- WordPress pre-build slider
- Leveraging Core Functionality in Icon Upload Plugin [closed]
- How can I chanage the user for the composer container in wp-env?
- Adding a navigation with wp_nav_menu() to a custom block in the site editor
- Why isn’t custom sidebar panel not showing up in the Gutenberg Editor?
- Ninja Forms: Front-End Forms, Post ID?