• Hi i want to redirect a page to the current author’s archive page using a shortcode, so it happens on any page i want it to, and if the user is not logged in it will redirect to the login page

    I have tried looking for this, but nothing comes up that relates to this

    • This topic was modified 1 year, 10 months ago by mightyx3n.
    • This topic was modified 1 year, 10 months ago by mightyx3n.
Viewing 1 replies (of 1 total)
  • Anonymous User 14808221

    (@anonymized-14808221)

    It is not the best idea to redirect using a ShortCode.

    It would be better to create a function which you can hook to template_redirect, conditionally.

    Something like this:

    
    function your_prefix_template_redirects() {
    
    	if ( is_page( array( 1, 3, 7 ) ) ) {// where 1, 3, 7 would be IDs of the pages you want this to happen
    		wp_safe_redirect( get_author_posts_url( get_the_author_meta( 'ID' ) ) );
    		die();
    	}
    
    }
    add_action( 'template_redirect', 'your_prefix_template_redirects' );
    

    Note, this code is untested, you should study the Documentation linked above, and use this first on a testing site, or at least on a live site with debug turned on and access to FTP to amend it for your needs.

    • This reply was modified 1 year, 10 months ago by Anonymous User 14808221.
Viewing 1 replies (of 1 total)
  • The topic ‘Redirect to current author archive’ is closed to new replies.