$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Password Protect content() on homepage|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Password Protect content() on homepage

matteradmin8PV0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

You 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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far