I am creating a simple 404 redirect plugin. I want the theme 404.php file to be override when I activate the plugin. There is a 404.php page in the plugin files. File path: plugins/myplugin/files/404.php

How to override 404.php file in theme files with 404.php in plugin folder (When I activate the plugin).

I just created the plugin and activated it. All codes are here:

function my_redicert_plugin() {
global $wpdb;

$table_namex = $wpdb->prefix . 'redirect_p';

$charset_collatex = $wpdb->get_charset_collate();

$sqlx = "CREATE TABLE $table_namex  (
    `id` mediumint(9) NOT NULL AUTO_INCREMENT,
    `mytext` longtext NOT NULL,
    `okbutton` longtext NOT NULL,
    UNIQUE KEY id (id)

require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sqlx ); 

register_activation_hook( __FILE__, 'my_redicert_plugin' );

add_action('admin_menu', 'ds_menux');

function ds_menux() {
    add_menu_page('404 Redirect', '404 Redirect', 'administrator', 'my-redirect-plugin', 'my_r_plugin', 'dashicons-admin-generic'); 

(Sorry my English.)

  • What exactly have you done? Show some code. Sep 28, 2017 at 10:40
  • @SamuelAsor I have just created the plugin yet. All I want is to change this 404 file when I activate this plugin. (I've added all the codes.)
    – Faruk
    Sep 28, 2017 at 10:46
  • See this plugin Sep 28, 2017 at 10:58

1 Answer 1


Template logic is primarily controlled by template-loader.php.

The part you are interested in would be get_404_template(), which passes on to generic get_query_template() with number of hooks to override the logic and result.

{$type}_template (so 404_template) filter would probably do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.