Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample plugin for redirecting a WordPress site to a specific URL.
<?php
/*
* Plugin Name:
* Plugin URI:
* Description:
* Version: 1.0
* Author:
* Author URI:
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
add_action(
'init',
function () {
global $pagenow;
// Allow requests to /wp-admin and wp-login so that admins can attempt to login
if ( 'wp-login.php' !== $pagenow && ! is_admin() ) {
wp_redirect( 'https://mynewsite.com', 301 );
exit;
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.