When you use WordPress plugins, you can add new functions to your website. But every plugin makes your website a bit slower. Instead of using plugins, you can use one plugin in combination with code snippets. This will keep your website fast and give you a nice overview of all the functionalities you add.
In this blog post, I want to share the best code snippets you can use for your blog website.
PHP Code Snippets
Redirect Non-Users To Other Page
add_action('template_redirect', 'redirect_non_logged_in_users');
function redirect_non_logged_in_users() {
// Check if the user is not logged in and is not accessing wp-login.php or wp-admin
if (!is_user_logged_in() && !is_page('wp-login.php') && !is_admin()) {
// Redirect to the specified external URL
wp_redirect('https://ferdy.ferdyishappy.com');
exit;
}
}



