First add the rewrite rule:
function wpse426504_add_rewrite() {
add_rewrite_rule( 'mycontent/events/([a-z0-9-]+)[/]?$', 'index.php?eventslug=$matches[1]', 'top' );
}
add_action( 'init', 'wpse426504_add_rewrite' );
function wpse426504_add_query_var( $query_vars ) {
$query_vars[] = 'eventslug';
return $query_vars;
} );
add_filter( 'query_vars', 'wpse426504_add_query_var' );
That’s the basics of it. If you need to add a new template to handle displaying everything, you’d then hook to template_redirect
.
Related Posts:
- How do you create a “virtual” page in WordPress
- Change the “page” slug in pagination
- Understanding add_rewrite_rule
- generate_rewrite_rules (action) vs add_rewrite_rule (function): which one is preferred?
- Rewrite Rules for Multiple (more than 2) Taxonomies
- add_rewrite_rule not loading correct page nor getting variables
- SEO Friendly URLs for my plugin categories
- How do I add a add_rewrite_rule without it redirecting?
- WordPress URL rewrite regex
- Getting add_rewrite_rule and add_rewrite_tag to work
- Blog installed in subdirectory but need to create pages in root. How to use permalinks?
- WordPress keeps writing rewrite rules to .htaccess
- WordPress Rewrite
- Custom rewrite rule for backend/admin?
- How to have multiple rewrite endpoints in the same URL?
- add_rewrite_rule is not taking effect in WordPress? .htaccess file doesn’t update
- Regionalised Content
- How to do Basic URL Rewrite Without Redirecting
- Add specific word to default page permalink
- URL Rewrite doesn’t work for nested pages
- Plugin action rewrite rule – non_wp_rules
- Map alt domain to specific section of website w/o MU
- Rewrite rule to load images from production does nothing
- Custom query_vars and parse_request on wp-admin
- Have two different URLs show the homepage
- My WP_options db rewrite_rules Does Not Work
- Custom rewrite_rules – only pass numbers and not alphabetic characters
- WP is ignoring .htaccess rewritten URL
- Rewrite ugly URL to clean URL
- Rewrite wp-login.php URLS to static pages?
- Rewrite custom post type URL parameters
- Changed pagination URLS to use p= instead of paged=
- Change pagination url format
- Rewrite: WordPress URL rewrite on Search
- WPML language switcher for custom rewrite rules
- How to write Rewrite rule for same path using Rewrite API?
- Multiple query vars sorting combination and url rewrite
- URL rewriting with custom user meta “/%shop_name%/gallery/%gallery%”
- WordPress keeps writing rewrite rules to .htaccess
- URL Rewrite and add_query_var not working
- How to add custom rewrite rules and point to specific templates
- Custom rewrite after the default term link URL
- How can I reduce the number of rewrite rules?
- Capturing /page-name/[0-99999] in both template and number
- Redirect old query string urls to new SEO urls
- custom wordpress rewrite
- Keep requested/entered url with add_rewrite_rule
- Get wordpress installation folder
- Bilingual WP site: How to achieve different URL sturcture rule based on its language?
- Name page template properly
- How can I create custom URL routes?
- Rewrite Rule for homepage not working correctly
- One off rewrite for single post-type slug (show normal page with same URL instead)
- Adding Rewrite URL for Base + Children Separately
- WP redirect rule doesn’t work
- URL rewrite in theme doesn’t seem to be working
- Rewrite rule that wp-login.php?action=register is left alone
- Trying to add array of paths to post permalink
- How to rewrite URL back to default custom URL if no destination found
- add_rewrite_rule() issue with parent/child/child page
- Dynamic URL with rewrite rule not working
- How can I add a vanity URL for admin-ajax.php Calls?
- Remove part from dynamic url and redirect
- How to get relative page for every post: /post-1/contact. /post-2/contact
- Rewrite rule can’t get the ID from rewrited
- Pretty URL via Rewrite
- URL rewrite problem in WordPress plugin
- WordPress Rewrite Rule to EITHER Match 1 or 2 Taxonomies when adding to URL
- WordPress numeric (yearly) page names / disable yearly archives
- Usw add_rewrite_rule to display frontpage on specific page
- “SAVE PERMALINKS” does more than FLUSH_REWRITE_RULES?
- Rewrite Rule added but showing 404 rather than specified page
- Blog List Page 404 With Custom Post Type Rewriting to Blog Parent
- Need help with custom rewrite rule
- Rewrite rules goes away
- WordPress doesn’t remember my custom rewrite rule
- Custom urls in WordPress involving page slugs
- how to change some of the rules in the database
- rewrite rules social share links
- Rewriting URLs with query strings and preserving them
- add_rewrite_rule is not fired
- Custom URL scheme – paramters on custom post type
- get_permalink is getting old rewrite rule
- Custom Rewrite for Profiles
- WordPress Custom Rewrite Rule
- What is the proper way to use add_rewrite_rule to remove the (question mark)?
- Rewrite function
- WordPress post-type create url rewriting
- help with rewrite_tag and rewrite_rule for custom page GET variables [duplicate]
- Use add_rewrite_rule to change subpage url
- Rewrite rule to simulate page hierarchy results in 404
- Rewrite URLs in a Custom Post Type with Multiple Taxonomies
- Rewrite rule giving 404 error
- add_rewrite_rule not working with custom variables
- WordPress picks a wrong template if ?cat= is used as URL parameter
- Standard Regex syntax doesn’t work in WordPress rewrite rule
- How to combine nearly identical custom rewrite rules for WordPress
- Is it possible to use the same slug structure for a taxonomy and for some pages?
- Nesting add_rewrite_rule() with custom page and subcategories
- openlitespeed rewrite rules conversion from apache