You need to register a ‘rewrite endpoint’ using add_rewrite_endpoint()
:
<?php
add_action(
'init',
function() {
add_rewrite_endpoint( 'play', EP_PERMALINK );
}
);
Now, after flushing permalinks, in whatever template or code you’re using for your products you can check this to determine whether the /play
version of the URL is being accessed:
<?php
if ( false !== get_query_var( 'play', false ) ) {
// True for mydomain.tld/product/play-and-win-samsung-galaxy-s22/play
} else {
// True for mydomain.tld/product/play-and-win-samsung-galaxy-s22
}
Related Posts:
- Is it possible for a plugin to register a page template file?
- Calling a function from functions.php in custom page/ blog post
- Using a Page Template Not in Theme
- Generating Multiple Divi Pages from Database
- A tool to analyze rewrite rules? [closed]
- Get page content using slug
- Change the_title() of a page dynamically
- How can I add an option to the Page Template list from a Plugin?
- How to Rewrite WordPress URL for a Plugin
- How to edit the properties of a page programmatically?
- Custom Rewriting to Plugin with Parameters
- Filter to change the content of 404 page
- Add rewrite rule in plugin: with .htaccess in plugin folder or using WordPress functions
- Removing rules from .htaccess
- Mapping multiple URLs to same page
- Pages 404 in wordpress
- How to create a dynamic page based on form data with a plugin?
- Use an empty page to build custom plugin output
- Dynamically override page.php or single.php with custom templates using function
- Dropdown list of pages to get page id to store in plugin options
- Rewrite Point Doesn’t Work on Custom Taxonomy
- Build dynamic page from cURL (HTML page) response with plugin
- Rewrite url for existing page without flush_rewrite_rules
- Load page template with custom content using a plugin
- Set a specific page as 404 – not found via my own plugin
- Custom rewrite rule serves content, but returns 404 error code
- How to Add Page Template from Plugin without Losing $this
- URL rewriting must be activated manually for my plugin
- Create a Page via plugin
- Dequeue theme stylesheets but keep widget styling on custom page template
- How to change the URL pattern for single post view
- How to display non-page / post content
- Why doesn’t flush_rewrite_rules run on plugin activation?
- Change template dynamically
- Create a custom page template inside my wordpress plugin
- Append country to ‘pretty’ url but serve same page
- Problem with parameters in url and pagination
- Set page template programaticlly in plugin
- How can I pass get_the_author_meta(‘user_email’) through the REST API?
- Can Page Templates be Applied to Archive and Post Templates?
- Secure Pages Best Practice
- How can I rewrite a URL to pass requests to a custom method via AJAX? (I can’t use admin-ajax.php)
- Adding rewrite rule dynamically
- rewrite URL based on selected taxonomy for post page
- Remove custom post type slug from URL and add taxonomy Slug
- Custom Plugin theme filter
- Plugin generated virtual pages
- Help writing custom function with rewrite endpoint that generates a page from dynamic content
- Possible to get all posts with my shortcode?
- add_rewrite_rule behaving strangely
- Add Password Generator on password protected page
- ECHO Executing 4 Times In Head
- WordPress pages are not published due to External database connection with WPDB class
- my basic php code producing unexpected results
- HowTo to add my rewrite rules at the beginning, redirect to the right page and flush the rules on plugin activation?
- Multiple array for post_content on plugin activation
- How can I add rewrite rules to a class-based plugin?
- How to output functions from plugin inside theme
- Best way to distribute templates and code accross multiple wordpress sites?
- How to list all images used on a specific page?
- Create fixed static pages
- configuration of .htaccess for add_rewrite_rule to make sense
- Plugin Development – Get Admin Url (Including cases where wp-admin is not used)
- Forward an old url rewrite scheme to a new one?
- How to remove/replace current page template?
- Rewriting Image URLs from dynamic to original
- Set page to draft on plugin deactivation
- Custom Path for a Plugin
- How to create archive page to add in menu
- Load specific page when a custom URL is hit
- Custom post type change permalink query
- Change cannonical URL after changing url with add_rewrite_rule()
- Plugin frontend page design irrespective of the theme used
- Disabling Yoast, All-in-One, and Rank Math on Certain Pages within a Plugin
- Conditionally check if page is using template from plugin directory
- WordPress custom url without using any of the custom tags given
- How to save multiple values in custom post type from front end to back end
- Using meta_key & meta_value in add_rewrite_rule
- Change Front page displays settings conditionally when user is online
- Can’t create a blank template
- How to pass a more variable with page/subpage in Wordprees URL?
- Page template compatibility with different themes
- How to add conent (text) to Add New pages form of admin in WordPress
- Rewriting URLs with a query string
- How can I send an id over the url?
- Custom slug in url for CPT and taxonomy
- add_rewrite_rule not working
- Mapping multiple URLs to same page
- Use custom clean URLs for a plug in
- How to Rewrite WordPress URL for a Plugin
- Virtual Page with Registration form
- Create pages for authors
- How to use permalink query to go to specific tabs in posts
- How to Rewrite WordPress URL for a Plugin
- redirect word-press page with page values
- How do I use (or mimic) document.getElementById() on a page loaded from WordPress database?
- URL rewrite parameter lost (add_rewrite_rule)
- Find Any Theme’s page.php File
- Custom rewrite, url path with parameters to a page
- Problem with Owl Carousel, infinite loop [closed]