You can filter 404_template
and return the path of your custom file from the plugin directory like this:
add_filter(
'404_template',
fn() => plugin_dir_path( __FILE__ ) . '404.php'
);
This hook exists only when a 404 happens, so you don’t need any custom detection.
Related Posts:
- Get page content using slug
- Change the_title() of a page dynamically
- How to edit the properties of a page programmatically?
- Filter to change the content of 404 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
- Is it possible for a plugin to register a page template file?
- Dropdown list of pages to get page id to store in plugin options
- Calling a function from functions.php in custom page/ blog post
- How do I approach removing menu items on the fly based on settings in my plugin?
- Custom rewrite rule serves content, but returns 404 error code
- Create a Page via plugin
- Secure Pages Best Practice
- Show custom data instead of 404
- Plugin generated virtual pages
- 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
- Create page (not the post type) dynamically
- Multiple array for post_content on plugin activation
- How to list all images used on a specific page?
- Create fixed static pages
- If $var is empty, return 404.
- Form submission to another page returning 404 error [duplicate]
- Set page to draft on plugin deactivation
- How to create archive page to add in menu
- Load specific page when a custom URL is hit
- Check current URL is 404 in pre_option_stylesheet filter hook
- Plugin frontend page design irrespective of the theme used
- Custom non-template page on front end fails to render
- Scripts/styles not loading on cloned WP Site when logged in
- How do I control the list of Pages an author can see?
- How to add conent (text) to Add New pages form of admin in WordPress
- auto create only 1 wp page in activate custom plugin
- Create pages for authors
- Plugin – Proper way to handle 404 pages?
- How do I use (or mimic) document.getElementById() on a page loaded from WordPress database?
- Using a Page Template Not in Theme
- Generating Multiple Divi Pages from Database
- Problem with Owl Carousel, infinite loop [closed]
- How to debug a plugin with Xdebug?
- Is there widely accepted phpDoc syntax for documenting which hook calls a function?
- Make Categories and Tags required in admin
- Getting wrong relationship value in $args in wp_Query?
- How to extend LINK TO functionality in ATTACHMENT DISPLAY SETTINGS
- How do I Make a Theme “plugin-ready”?
- How to iterate through custom posts and add the title to an array
- How to Structure a New Role/Capability Scheme?
- How to create Image gallery Metabox in wordpress [closed]
- Is it possible to create an action hook using do_action() within add_action()?
- Custom user profile, registration, login page with theme
- Plugin Sidebar is not Saving Meta Attribute to Post/Page after “Update”
- WordPress 2.8 Widget API is suitable for Worpress 3.1.4 plugins development?
- Need specific kind of “Poll Voting” for WordPress [closed]
- Install widget on plugin activation
- Error “Call to a member function switch_to_locale() on null” during insert_with_markers
- multiple functions with same filter
- Calling plugins API within a theme
- Generate dynamic page through data from another page
- Does WordPress’s HTTP API use any caching?
- query users by role
- call_user_func_array() expects parameter 1 to be a valid callback, array must have exactly two members
- How to Create Custom HTML Tag on Editor in `Text(HTML)` mode
- null callback in add_settings_section
- Is there a Filter that I can use to filter the tags before they are inserted in to the database?
- How long should it take for a plugin to fully load into the WordPress.org plugin repository?
- How can I pass get_the_author_meta(‘user_email’) through the REST API?
- get post attachment using ajax
- How to enqueue or include json file to a plugin
- Search and Filter
- Show error, when selecting image in WordPress media uploader if params mismatch
- Trying to code a simple plugin, infinite loop?
- How to exit a plugin’s execution mid-stream?
- Issue with contextual help overwriting existing content
- Redeclaring a plugin function within a class
- Using a custom shortcode from within the template of a shortcode plugin
- enqueue script/style plungin development
- Trying to get class to instantiate ONCE (or, “why do I keep punching myself in the head?”)
- How to Add a Custom Size for Thumbnails for WP – Gallery
- Will I get an error if I try unscheduling a WP Cron scheduled task that wasn’t scheduled?
- Conditional Generation of Image Sizes using add_image_size
- Plugins and caching
- Display time difference (6 hours ago) in a Soliloquy caption
- Empty Array is Giving Warning for array_merge()
- Toolbar Hidden in a Virtual Page
- Is it possible to have instead mypage.com/?page_id=81 to have mypage.com/cool/?
- Translations only load from `wp-content/languages/plugins` but not from the plugin’s languages folder
- GET request return value as error instead of success
- How to update global variables in plugin activation callback?
- How to include a page template and template part into my plugin
- WP_Fatal_Error_Handler OR WP_Error OR try/catch
- Why does do_action pass a blank string as the first parameter if no $arg is set?
- Multiple instances of $opt_name in redux framework
- The Events Calendar featured image as body background?
- Pass javascript result to shortcode executer function
- problem with blank page
- Cannot echo a JS variable to a jQuery plugin coming from wp_localize_script
- first_name property missing inside register_user action hook
- Reinitiate Gutenburg’s blocks using javascript