Skip to main content
deleted 4 characters in body
Source Link
mmm
  • 3.8k
  • 3
  • 16
  • 22

WordPress beginner here. I'm trying to check if a shortcode exists in the page being requested by the user, then if it does, redirect if the user is not signed in.

    function redirect_to_home() {
  if (has_shortcode(get_the_content(), 'shortcode')) {
    if(!is_admin() && !is_user_logged_in()) {
      //redirect
      exit();
    }
  }
}
add_action('template_redirect', 'redirect_to_home');

Is this close? And currently this code is placed in the functions.php files, is this correct?

WordPress beginner here. I'm trying to check if a shortcode exists in the page being requested by the user, then if it does, redirect if the user is not signed in.

    function redirect_to_home() {
  if (has_shortcode(get_the_content(), 'shortcode')) {
    if(!is_admin() && !is_user_logged_in()) {
      //redirect
      exit();
    }
  }
}
add_action('template_redirect', 'redirect_to_home');

Is this close? And currently this code is placed in the functions.php files, is this correct?

WordPress beginner here. I'm trying to check if a shortcode exists in the page being requested by the user, then if it does, redirect if the user is not signed in.

function redirect_to_home() {
  if (has_shortcode(get_the_content(), 'shortcode')) {
    if(!is_admin() && !is_user_logged_in()) {
      //redirect
      exit();
    }
  }
}
add_action('template_redirect', 'redirect_to_home');

Is this close? And currently this code is placed in the functions.php files, is this correct?

Source Link

redirect if shortcode exists

WordPress beginner here. I'm trying to check if a shortcode exists in the page being requested by the user, then if it does, redirect if the user is not signed in.

    function redirect_to_home() {
  if (has_shortcode(get_the_content(), 'shortcode')) {
    if(!is_admin() && !is_user_logged_in()) {
      //redirect
      exit();
    }
  }
}
add_action('template_redirect', 'redirect_to_home');

Is this close? And currently this code is placed in the functions.php files, is this correct?