admin管理员组文章数量:1130349
I need to password protect several pages and various areas of my templates if the page had a password enabled. This I can do on all subpages but on the homepage it's just not working.
I do not want to whole site password protected, which many plugines seem to do - the built-in WP password protection is fine for this purpose apart from the homepage issue. When the visitor lands on the site, they can see elements of the page but some content is hidden. The content needs to be unlocked by just a password and not a registered WP account username/password.
I assume the page used as home is treated differently than "normal" pages.
The only thing I can think of is to instantly redirect the homepage to a "normal" pge that looks identical - then the password protection function would work?
Google just offers either protecting the whole site (ie all you see in a login page) or protecting a normal page or using registered accounts to unlock content.
I need to password protect several pages and various areas of my templates if the page had a password enabled. This I can do on all subpages but on the homepage it's just not working.
I do not want to whole site password protected, which many plugines seem to do - the built-in WP password protection is fine for this purpose apart from the homepage issue. When the visitor lands on the site, they can see elements of the page but some content is hidden. The content needs to be unlocked by just a password and not a registered WP account username/password.
I assume the page used as home is treated differently than "normal" pages.
The only thing I can think of is to instantly redirect the homepage to a "normal" pge that looks identical - then the password protection function would work?
Google just offers either protecting the whole site (ie all you see in a login page) or protecting a normal page or using registered accounts to unlock content.
Share Improve this question asked Nov 21, 2018 at 13:14 CuCoCuCo 33 bronze badges1 Answer
Reset to default 0You can make the homepage password protected by creating a page and selecting it in the admin Settings > Reading > Homepage Displays. Then on the page settings make it password protected.
Then create a template called front-page.php and use conditionals to show/hide the content.
For Example...
if ( ! post_password_required( $post ) ) {
// Password Protected Content
}else{
// Password Form
echo get_the_password_form();
}
More info on password protected pages.
Note: If you have already entered your password, you can delete your cookies and refresh the page to see the password form again.
I need to password protect several pages and various areas of my templates if the page had a password enabled. This I can do on all subpages but on the homepage it's just not working.
I do not want to whole site password protected, which many plugines seem to do - the built-in WP password protection is fine for this purpose apart from the homepage issue. When the visitor lands on the site, they can see elements of the page but some content is hidden. The content needs to be unlocked by just a password and not a registered WP account username/password.
I assume the page used as home is treated differently than "normal" pages.
The only thing I can think of is to instantly redirect the homepage to a "normal" pge that looks identical - then the password protection function would work?
Google just offers either protecting the whole site (ie all you see in a login page) or protecting a normal page or using registered accounts to unlock content.
I need to password protect several pages and various areas of my templates if the page had a password enabled. This I can do on all subpages but on the homepage it's just not working.
I do not want to whole site password protected, which many plugines seem to do - the built-in WP password protection is fine for this purpose apart from the homepage issue. When the visitor lands on the site, they can see elements of the page but some content is hidden. The content needs to be unlocked by just a password and not a registered WP account username/password.
I assume the page used as home is treated differently than "normal" pages.
The only thing I can think of is to instantly redirect the homepage to a "normal" pge that looks identical - then the password protection function would work?
Google just offers either protecting the whole site (ie all you see in a login page) or protecting a normal page or using registered accounts to unlock content.
Share Improve this question asked Nov 21, 2018 at 13:14 CuCoCuCo 33 bronze badges1 Answer
Reset to default 0You can make the homepage password protected by creating a page and selecting it in the admin Settings > Reading > Homepage Displays. Then on the page settings make it password protected.
Then create a template called front-page.php and use conditionals to show/hide the content.
For Example...
if ( ! post_password_required( $post ) ) {
// Password Protected Content
}else{
// Password Form
echo get_the_password_form();
}
More info on password protected pages.
Note: If you have already entered your password, you can delete your cookies and refresh the page to see the password form again.
本文标签: Password Protect content() on homepage
版权声明:本文标题:Password Protect content() on homepage 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749156275a2324645.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论