[Support request] Create a redirection for a page

Home Forums Support [Support request] Create a redirection for a page

Home Forums Support Create a redirection for a page

Viewing 10 posts - 16 through 25 (of 25 total)
  • Author
    Posts
  • #1009485
    Esteban

    Still doesnt work…

    What we can do?

    #1009536
    David
    Staff
    Customer Support

    Can you show us all the redirect functions you have added. After adding code in the forum, please highlight all the code and click the code button in the editor.

    #1009564
    Esteban

    Sure,

    1)

    add_action( 'wp', 'redirect' );
    function redirect() {
      if ( is_page('mi-cuenta') && !is_user_logged_in() ) {
          wp_redirect( home_url('/acceder') );
          die();
      }
    }

    2)

    //Ocultar admin bar a todos los suscriptores
    add_action('after_setup_theme', 'bld_ocultar_admin_bar');
    function bld_ocultar_admin_bar() {
    if (current_user_can('subscriber')) {
    add_filter( 'show_admin_bar', '__return_false' );
    }
    }
    

    3) This one is the one that do not work

    add_action( 'template_redirect', function() {
        if ( is_page( 'cursos' ) && ! is_user_logged_in() ) {
            wp_redirect( home_url( '/acceder' ) );
            die();
        }
    } );
    #1009571
    David
    Staff
    Customer Support

    For #3 try:

    add_action( 'template_redirect', function() {
        if ( is_post_type_archive( 'sfwd-courses' ) && ! is_user_logged_in() ) {
            wp_redirect( home_url( '/acceder' ) );
            die();
        }
    } );

    I assume sfwd-courses is the name of your Courses archive?

    #1010579
    Esteban

    Now it is working!

    Thanks you so much for you support!

    #1010585
    David
    Staff
    Customer Support

    Glad to be of help!

    #1646544
    Joe

    Hi,
    This code works great for me for a single page, but I’m looking to do it for multiple pages so I can set it once and forget about it.

    Could I enable this for a content type instead of a single page?
    Or if not, how about a wildcard? eg mysite.com/restricted-page/*

    Thanks! Joe

    #1646700
    David
    Staff
    Customer Support

    Hi there,

    you can use any of the WP Conditional Tags:

    https://codex.wordpress.org/Conditional_Tags

    What is determining the ‘restricted-page’ term ?

    #1650902
    Joe

    Thank you David,

    I am using a custom post type, so I can add post_type_exists from the conditional tags.

    I had made a post type called ‘Student Pages’ for logged in students, so I can use this to redirect if they aren’t logged in.

    Thanks for the support! This is resolved.

    Joe

    #1651358
    David
    Staff
    Customer Support

    Glad to hear that!

Viewing 10 posts - 16 through 25 (of 25 total)
  • You must be logged in to reply to this topic.