on my website I restricted 3 pages (IDs 861, 869, 931) to all non-registered users but I’m having a problem, those pages will always redirect the user to the login page (even if I’m logged in), what I’m doing wrong?

Here’s the code, a little help would be greatly apprecieated

add_action( 'template_redirect', 'redirect_to_specific_page' );

function redirect_to_specific_page() {

if ( is_single('861') or is_single('869') or is_single(931) &&
!is_user_logged_in() ) {

wp_redirect( 'http://mywebsite.com/login', 301 ); 

Read more here: wp redirect to same page in php


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: