douhuantui6259 2018-04-13 08:40 采纳率: 100%
浏览 50
已采纳

从模板重定向到父页面 - Wordpress

I got a template that i use like a block in his parent page, and i would like to redirect this template.

Could you tell me how can i redirect my page who got a template name to his parent page ?

I don't know how i can detect the template in my hook ...

i would like to do something like that :

add_action( 'template_redirect', 'wpnc_redirect_single' );
function wpnc_redirect_single() {
    $queried_post_type = get_query_var('post_type');
    if ( is_single() && 'reference' ==  $queried_post_type ) {
        wp_redirect( home_url(), 301 );
        exit;
    }
}

But here it's for a custom type

Thanks

  • 写回答

1条回答 默认 最新

  • doushao1948 2018-05-04 13:07
    关注
    if (is_page_template("templates/template-pdf.php")){
    wp_redirect( home_url(), 301 );
     exit;
     }
    

    Like that

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?