hooks - Remove Header and Footer if user is not logged on

Using Hook, is there a way to remove the Header and Footer from the specific page that is trying to access by users, if

Using Hook, is there a way to remove the Header and Footer from the specific page that is trying to access by users, if the current user is not logged on?

function footer_header_remove() {
    if(!is_user_logged_in() && is_page('the-page')){
       //Remove Header and Footer of "the-page"
    }
}
add_action('???????????', 'footer_header_remove');

Using Hook, is there a way to remove the Header and Footer from the specific page that is trying to access by users, if the current user is not logged on?

function footer_header_remove() {
    if(!is_user_logged_in() && is_page('the-page')){
       //Remove Header and Footer of "the-page"
    }
}
add_action('???????????', 'footer_header_remove');
Share Improve this question asked Jun 30, 2020 at 7:33 PolarPolar 1311 silver badge13 bronze badges 1
  • Do you have a page template for that page or? – Milosh N. Commented Jun 30, 2020 at 9:09
Add a comment  | 

1 Answer 1

Reset to default 2

You have a lot of ways to do this.

The first important thing is next: You must have a header or a footer (default header and footer, from WP) if you want to have functionality.

E.g If you are loaded scripts or styles in function.php they will be broken, because you can't load them without header or footer.

You can create more types of footers or headers where if you have one page or one type of page templates you can do that on this way:

// your example-template.php
    
<?php /* Template Name: Example Template */
if(!is_user_logged_in()) {
    get_header('blank-header');
}   

And for the footer do the same thing.

In your case, where you want to load or not header and footer from the function, you can use 'init' hook or you can use the last hook before loading the template is 'template_redirect' that is your choice.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742307025a4419143.html

相关推荐

  • hooks - Remove Header and Footer if user is not logged on

    Using Hook, is there a way to remove the Header and Footer from the specific page that is trying to access by users, if

    14小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信