How To Exclude The Pages/Posts From Force Login Feature (Hook)

Force Login is a premium feature of LoginPress. It forces users to log in before viewing the contents of your site. When you enable the option of Force Login, a user will be redirected to the login page to log in before viewing your site’s content. 

It is designed to create a membership feel to your WordPress site, making users Login to get inside the WordPress website.

Force Login - LoginPress's Pro Feature
Force Login - LoginPress's Pro Feature

Note: You can learn more about the Force Login feature to understand its working.

Suppose you want to exclude a specific page, i.e., Privacy Policy, from the Force Login, what would you do?

This knowledge base will provide you with an action Hook that will help you exclude specific pages/posts from the Force Login feature to engage and improve the user’s experience.

Make sure to read this doc till the end. Let’s get started! 

Exclude The Pages/Posts from Force Login Feature with Hook

Suppose you want to exclude the specific pages or posts, i.e., the Privacy Policy, from the LoginPress Force Login feature. For this purpose, you’ll need to update the code to your website theme's functions.php file (provided below in this documentation). It will enable users to view the Privacy Policy page without the need to log into the website/blog to see it.

To do this, go to the left sidebar of your WordPress admin dashboard, navigate to Appearance, and click the Theme File Editor option.

Theme File Editor

On the next screen, click the Theme Functions on the right-hand side. Scroll down to the bottom of the functions.php file screen, paste the code, and click the save changes.

Note: It’s recommended to use a child theme to edit the functions.php file instead of the parent theme. There are chances to lose the modified code when you update your theme. It might cause some adverse effects on your website.

Here is the code for you:

function loginpress_exclude_forcelogin_callback() { 
    return array( 'privacy-policy', '1' ); 
    // Here '1' is the ID of the post and 'privacy-policy' is slug of the page.
add_filter( 'loginpress_exclude_forcelogin', 'loginpress_exclude_forcelogin_callback' );

Note: Here, ‘privacy-policy’ is the slug of a post or page, and ‘1’ is the ID of the post/page. It means you can give both slugs and IDs of post/page in this comma-separated array.

Slug of post or post-id

To return a single value or array. You can return the slug of the post or the post-id. With the help of the loginpress_exclude_forcelogin hook, you can prevent pages/posts from Force Login features.

That’s all! We hope you now understand how to exclude posts and pages from the Force Login feature of LoginPress using the hook provided above.

If you have any doubts or questions, please don’t hesitate to contact our support forum. We will be happy to help you with it.

Still stuck? How can we help?

Updated on January 3, 2024

LoginPress Support
triangular shape yellowish icon

Frequently Asked Questions (FAQs)

These FAQs answer the most common questions about our WordPress custom login page plugin.

three shapes icon

Where can I get support for LoginPress?

If you need help with LoginPress, you can contact us here. We’ll be happy to answer any questions about the plugin.

Do you have an affiliate program?

Yes, we have an affiliate program that you can sign up for here. As an affiliate, you’ll earn a commission on every sale you refer to us.

Do you offer refunds?

Yes, we offer a 14-day money-back guarantee on all of our plans. If you’re unsatisfied with LoginPress, simply contact us within 14 days of your purchase, and we’ll process a refund.

Can I upgrade my license after my initial purchase?

Yes, you can upgrade your LoginPress license at any time. Simply log into your account and go to the My Downloads page. From here, you can upgrade your license and download the latest version of the plugin.

Will LoginPress slow down my website?

No, LoginPress will not slow down your website. The plugin is lightweight and only loads the necessary files when someone tries to access your login page.

three shapes icon

If you Still have Questions?

Get In Touch