I was wondering why (and how to) restricting pages by the following criteria does not work. I wanted to restrict the contact page due to spam. The code is being added and activated on front-end using the Code Snippets plugin:
function contactusnot()
{
if ( !is_user_logged_in() && (is_page( 220 ) || is_page( 'Contact us' ) || is_page( 'contact-us' )))
{
header("Location: https://google.com/");
exit();
}
}
add_action('init', 'contactusnot');
I've tried removing the function, hoping it will force the filter to work before anything else and also using only the ID/slug/title one by one. Now working for my Woocommerce site.
init
hook, which means your code wouldn't execute. Try moving the code outside of the hook callback, and see what happens.