How to Hide or Change Password Protected Message and Form in WordPress

In this tutorial, we are going to show you how you can change password-protected message and the form in WordPress. WordPress allows you to have password-protected posts or pages. This basically means that only people who have the defined password will be able to access the content of that page/post.

The default, the message for this page will read “This content is password protected. To view it please enter your password below:”.

But sometimes, you might want to change the default password-protected message in WordPress.

First of all, to create a password-protected page, we simply edit the page/post, we click the ‘Edit’ link next to ‘Visibility’ on the right sidebar, select the ‘Password protected’ radio button and we can define a password as shown below:

Then when someone visits the page is will look something like this:

How to Change the Default Message on the Password Protected post/page in WordPress

To do this, we can simply add the following code to our functions.php file:


/**
 * Password Protected Message
 */

function my_custom_password_form() {
  
    global $post;

    // Custom logic for the message
    $password_form_message = 
    __( '<p id="private-area-message">This is my new message for the protected area. If you would like access to this page, please send an email to <strong><a href="[email protected]">[email protected]</a></strong></p>' );

    // Put together the custom form using the dynamic message
    $label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
    $form = '<div class="container"><form class="protected-post-form" action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
    ' . $password_form_message . '
    <label id="password-label" for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" class="pw-window" type="password" size="20" /><input type="submit" class="btn btn-large" name="Submit" value="' . esc_attr__( "Submit" ) . '" />
    </form></div>
    ';
    return $form;

}
add_filter( 'the_password_form', 'my_custom_password_form' );

After you have added this, your password-protected page will look as follows:

We also included the form as well so we can make changes to the form label and submit input value.

Hiding the Password Protected Message

To do this, we can use the same code that we used above, the only thing we need to change is the $password_form_message value by simply setting this to '' (empty) as shown below:


      $password_form_message = 
        __( '' );

And that’s basically it, pretty simple, right? We hope this has helped – if you need any assistance, feel free to drop a comment below.

 

Silva Web Designs - Profile

Posted by: Silva Web Designs

Nathan is the Founder of Silva Web Designs. He is passionate about web development, website design and basically anything digital related. His main expertise is with WordPress, Magento, Shopify as well as many other frameworks. Whether you need responsive design, SEO, speed optimisation or anything else in the world of digital then get in touch. If you would like to work with Nathan, simply drop him an email at [email protected]

It’s good to share

How to Change Your Default Category From “Uncategorized” in WordPress

For this tutorial, we will show you how to change the WordPress default category from “Uncategorized” to another category of your choice.

But why would I want to change this?

Categories are a type of WordPress taxonomy that helps users organise their posts or utilise them for filtering. By default, WordPress sets the default category automatically; this is defined as “Uncategorized”. With this, it becomes mandatory to manually select the desired category before publishing any new post. It’s a minor step, but it can quite frequently disorganise your website if you forget to update the post category on occasions.

The good news is, we can change the default category to any other category you want. For example, if you add a Category called “News”, we can make this the default and even remove the “Uncategorized” category.

Here are the 6 steps to change your default WordPress Category

1. Login to your WordPress Dashboard.

2. Navigate to Posts > Categories from the left side menu bar.

3. Add a new category that you would like to make your default category.

4. Select Writing > Settings from the left hand side bar menu.

5. Change the Default Post Category from “Uncategorized” to your newly preferred default category using the drop down menu.

6. Click Save Changes and that’s all there is to it! Your new posts will automatically select your new chose default category.

Conclusion

Changing the default category isn’t difficult when you follow the above steps, if you’ve not done it before you may not know where to look.

You might wonder why it matters… Well, having categories defined as “Uncategorized” doesn’t really give the user any idea of the blog posts they will reading. So having properly defined categories is always better not only for your website users, but using this along with tags will always help your websites crawl abilities by search engines. Categories and Tags are great elements to improve rankings and search visibility with websites today.

We hope you enjoyed this article, happy coding everyone!

 

Silva Web Designs - Profile

Posted by: Silva Web Designs

Nathan is the Founder of Silva Web Designs. He is passionate about web development, website design and basically anything digital related. His main expertise is with WordPress, Magento, Shopify as well as many other frameworks. Whether you need responsive design, SEO, speed optimisation or anything else in the world of digital then get in touch. If you would like to work with Nathan, simply drop him an email at [email protected]

It’s good to share