How to Customize Password protected post in wordpress

0 Flares Facebook 0 Google+ 0 0 Flares ×

Recently one of my client came through this requirements where he require some text on password protected page or post but was wondering how they can do that. this part require some initial knowleadge about wordpress theme because you have to add some php code in your theme file. please follow below steps to achieve this

1. Create Password protected page or post

2. Custom fields

Custom fields provide some additional functionality in wordpress where we can customize every page or post. Generally this option available in wordpress in visibility mode but if you don’t see custom fields you can check out our video about how to enable custom fields in wordpress. so to show text on password protected post create new custom field called “allowed_text“. you can name it anything as you like but for sake of simplicity I am using this text. after entering new custom field input its value in right textbox. click on Add custom field button.

3. Theme Modification

At last you require a little theme adjustment to show above text in your page or post. you have to follow below path in your Admin dashboard. Appearance-> Theme editor. you will see all theme files here in right panel with code editor window in the left. click on Page Template(page.php) from right and search for this text the_content(); 

Now paste below code just before this line

                     if ( post_password_required()){
                     $allowed_text = get_post_meta($post->ID, ‘allowed_text’, true);
                         echo $allowed_text ;

Save your theme file.

You are done with your changes. Hit your page where you want to see your text on password protected page.




0 Flares Facebook 0 Pin It Share 0 Google+ 0 0 Flares ×