That function should work equally well if included in a plugin. template_redirect is an action that fires any time WP parses a URL, it’s not exclusive to themes.
Related Posts:
- A tool to analyze rewrite rules? [closed]
- WordPress Plugin Development – Headers Already Sent Message
- Making a plugin file accessible via url rewrite?
- Clarity needed on usage of multiple 403 forbidden header() functions at the beginning of the plugin files
- How to Rewrite WordPress URL for a Plugin
- Headers already sent error with CSV export plugin
- Custom Rewriting to Plugin with Parameters
- Get file headers in custom file
- Using ob_start() in plugin
- Adding custom code into header.php using a plugin
- 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
- How can I change HTTP headers only to posts of a specific category from a plugin
- The plugin generated 80 characters of unexpected output!
- Rewrite Point Doesn’t Work on Custom Taxonomy
- Rewrite url for existing page without flush_rewrite_rules
- Custom rewrite rule serves content, but returns 404 error code
- URL rewriting must be activated manually for my plugin
- Cannot modify header information – headers already sent by pluggable.php
- Header Button Chance Polylang Elementor
- How to change the URL pattern for single post view
- Why doesn’t flush_rewrite_rules run on plugin activation?
- Redirect traffic to plugin
- An echo line in a transition_post_status action leads to “cannot modify header information – headers already sent by”
- Proper way to pass credentials in a custom login form to avoid “headers already sent”
- Append country to ‘pretty’ url but serve same page
- How To Consistently Enforce Rewrite Rule in Plugin Development
- 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
- Serve text/html from wp-json API via WPEngine, headers not being set properly
- Remove custom post type slug from URL and add taxonomy Slug
- Help writing custom function with rewrite endpoint that generates a page from dynamic content
- How to give a download link to a .csv file from the custom plugin?
- Possible to get all posts with my shortcode?
- add_rewrite_rule behaving strangely
- HowTo to add my rewrite rules at the beginning, redirect to the right page and flush the rules on plugin activation?
- Create page (not the post type) dynamically
- How can I add rewrite rules to a class-based plugin?
- Adding custom stylesheet into header.php using a plugin
- 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?
- Rewriting Image URLs from dynamic to original
- Need Help Determining Where Header Error is Happening
- Custom Path for a Plugin
- Why does website stretch and white space on load? [duplicate]
- Downloading File via headers doesnt work
- Custom post type change permalink query
- WordPress Favicon not Working For Images/Videos/PDFs
- Change cannonical URL after changing url with add_rewrite_rule()
- Disabling Yoast, All-in-One, and Rank Math on Certain Pages within a Plugin
- WordPress custom url without using any of the custom tags given
- Two same AJAX calls – one is working, other doesn’t
- Using meta_key & meta_value in add_rewrite_rule
- Some data has already been output, can’t send PDF file – fpdf issue in WordPress
- Headers already sent on custom plugin (Export function)
- How to pass a more variable with page/subpage in Wordprees URL?
- Any way to make Apache’s internal redirect work?
- 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
- 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
- URL rewrite parameter lost (add_rewrite_rule)
- Custom rewrite, url path with parameters to a page
- Why is there a bunch of WordPress HTML code in my browser CSV download?
- Difference Between Filter and Action Hooks?
- framework for plugin/theme options panel? [closed]
- How to validate custom fields in custom post type?
- How to Use Checkbox in Custom Option Page Using The Setting API
- Get List of Registered Meta Boxes and Removing Them
- How should one implement add_settings_error on custom menu pages?
- What is the difference between esc_html and wp_filter_nohtml_kses?
- Explanation of the “posts_join” and “posts_fields” filter hooks?
- Extend a class plugin
- Slow WP_query due to nested wp_query. Need Suggestions
- How to modify product page for Jigoshop
- Is @wordpress/env locked to node v14 or can I also use node v16?
- Create a custom capability to allow an ‘Editor’ to edit only ‘Subscriber’ users
- How to create a page with a form programmatically in WP?
- jQuery instantly executes (a button click and css change) on load
- How to make my shortcode load scripts and styles, from within the plugin?
- get_avatar filter in WordPress 4.4, how to filter properly
- How to make a cronjob type plugin
- Update plugin settings option_name for big plugin update
- How to get inserted row IDs for bulk/batch insert with wpdb query?
- BuddyPress and namespacing
- Get the post ID only off single page
- Page reload occurs before request finishes
- PHP Fatal error when using plugin_basename
- Declaration of mandoe_menu_walker::start_el(&$output, $item, $depth, $args) must be compatible with Walker::start_el(…)