Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Created January 31, 2019 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save wpscholar/ecbc78f174c2ab74bae8f07f8901c1cd to your computer and use it in GitHub Desktop.
Save wpscholar/ecbc78f174c2ab74bae8f07f8901c1cd to your computer and use it in GitHub Desktop.
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