How to restrict access to a page?

admin2025-06-05  2

I am developing a page in WordPress. In functions.php file I have this:

function feed_add_notmusa() {
  add_feed('mypage', 'mypage_function');
}

function mypage_function() {
  get_template_part('/mypage');
}

But how can I restrict access to /mypage so only logged in users can access?

Could you please help me?

I am developing a page in WordPress. In functions.php file I have this:

function feed_add_notmusa() {
  add_feed('mypage', 'mypage_function');
}

function mypage_function() {
  get_template_part('/mypage');
}

But how can I restrict access to /mypage so only logged in users can access?

Could you please help me?

Share Improve this question edited Dec 3, 2018 at 23:23 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Dec 3, 2018 at 20:50 skycomputer2skycomputer2 1033 bronze badges 1
  • 1 get_template_part doesn't take a URL path as a parameter, it takes a php template file name, the / is not needed. It will try to load childtheme/mypage.php and then parenttheme/mypage.php if it doesn't exist – Tom J Nowell Commented Dec 3, 2018 at 21:48
Add a comment  | 

1 Answer 1

Reset to default 1

Try this: is_user_logged_in

function mypage_function() {
  if( is_user_logged_in() ) {
    get_template_part('mypage');
  }else{
    echo 'please login for awesomeness';
  }
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749130565a316621.html

最新回复(0)