Welcome to Dagon Design. In addition to free scripts, WordPress plugins, and articles, we offer a variety of services including custom theme design, plugin creation, and PHP scripting. Contact me for more information.

Updated Sunday, February 22nd, 2009 at 8:20pm

Show the Intro to Password Protected Posts in WordPress

This is a small hack for WordPress that allows you to show the first part of password protected posts. It will display the content you have before the ‘more’ tag, followed by the standard password box. I wrote this up for a member of the WordPress forum, and I thought I would share it here. Update: Instructions are now provided for WordPress 2.2

Before you begin

The instructions below have been verified in WordPress versions 2.0 through 2.8. The only difference between these versions is the file you have to edit.

Instructions

For WordPress 2.0 or 2.1, open /wp-includes/template-functions-post.php

For WordPress 2.2 through 2.8+, open /wp-includes/post-template.php

Find the following text:

$output = get_the_password_form();
return $output;

Replace it with this:

$content = $pages[$page-1];
$content = explode('<!--more-->', $content, 2);
$output = "";
$output .= $content[0];
$output .= get_the_password_form();
return $output;

This next step is optional, but I think it makes it nicer.

In the get_the_password_form function, find the following text (may vary between versions):

This post is password protected.

And replace it with this:

The rest of this post is password protected.

Or whatever text you would like it to show.

  If you have found this page useful, please consider donating. Thanks!

  1. Ah well your comment! I did you good!VBDE

  2. I think that places like Facebook, i.e., the social networks that demand a transparent ‘self’ associated with the offline identity, Handbags

  3. Ad oggi uno dei marchi più grandi del mondo della moda, pelletteria Gucci è avviato, che sfruttano quando Gucci è stata fondata nel 1921,Handbags

  4. E qui viene il Moncler Piumini , i piumini che sono fatti da prima classe verso il basso che fornisce leggero e caldo allo stesso tempo. Moncler Giubbotto sono stati approvati da parte del mercato che sono le giacche più adatto per inverni freddi e l’abbigliamento invernale che ti fanno distintivo. 2011 Moncler Vendita La varietà di stoffe sicuramente incontrare personaggi speciali dei clienti ‘.

  5. I always thought he was well. But sometimes that is so, people do not know how to do. . Do you think? ?

  6. accessories no less color in clothing, bicycle chain is the most exciting theme pearl necklace and bracelet. Full of childlike, and Magnificent.

  7. I wonder whether the me-cult is able to reconcile itself with the thought that it might not always be in the right, and that ‘they’ might have a role in helping form their ideas.

  8. I think that places like Facebook, i.e., the social networks that demand a transparent ‘self’ associated with the offline identity,

  9. Ad oggi uno dei marchi più grandi del mondo della moda, pelletteria Gucci è avviato, che sfruttano quando Gucci è stata fondata nel 1921,

  10. Accessori da uomo tendenza, corrispondono alla moda perfetta per piccoli dettagli della transazione con un design semplice

  11. Ad oggi uno dei marchi più grandi del mondo della moda, pelletteria Gucci è avviato, che sfruttano quando Gucci è stata fondata nel 1921, un prodotto importante. Per celebrare il 90 ° anniversario di Gucci deliberatamente emessi chiamato “gucci 2011“, serie di nuovi modelli di lusso per uomo e donna. Questi sono in edizione limitata: l’utilità di queste Gucci Borse a mano di bambù o di coccodrillo, grande arco colori dal marrone scuro, rosso ciliegia al verde scuro. Gucci (Gucci) 2011 e le tendenze autunno inverno Baoxie semplici ed eleganti nella forma e nel design, con un tono seppia low-key di lusso.Economico Scarpe Gucci Accessori da uomo tendenza, corrispondono alla moda perfetta per piccoli dettagli della transazione con un design semplice …

  12. Ouyang Kun said that Coach in US

  13. can help me .thanks

  14. very nice .for yom

  15. The discount Christian Louboutin pumps are comfortable and fashion. There are all kinds of styles for you choose. The shoes with top qualities and competitive prices

  16. goos ness

  17. Thanks for the article, I’ll think about what you mentioned in it. It’ an interesting point of view.

  18. nthbtfg Nice hosting! It’s my first time to read like this article. 
    .	
    

  19. This is a wonderful site!gheyhr yhre

  20. Thank you so very much for taking the time to share…very useful, indeed!gii

  21. Thanks for a nice share you have given to us with such an large collection of information dfffd

  22. Each of the help are truly very appreciated.

  23. the idea of using password do help for security as anyone could have do changes in specific matters.

  24. I think password protection should become easier to use as it really help to assure secure use of the system.

  25. When will it Exprire?

    That is when Password protection value Expire…?

  26. Hello – great tip, just wondering if it is possible to hide the text more tag after somehow? as I am using a secret question as a password.

  27. great tutorials, its work also on wordpress 3.0+ above, thanks!

  28. Thanks for posting this article. I am definitely tired of struggling to find relevant and intelligent commentary on this subject. Everyone nowadays seem to go to extremes to either drive home their viewpoint or suggest that everybody else in the globe is wrong. Thanks for your concise and relevant insight.

  29. 60
    sun

    Very interesting discussion glad that I came across such informative post. Keep up the good work friend. top 10 golf trolleys

  30. There are lot of stuffs which need to be protected in order to have better use.

  31. 58
    health administration

    you give so many great tips especially since I use word press and the plug-in section of your blog is great. some of the tips i get here I can’t find anywhere else. health administration

  32. New scheme has always been appreciated by the readers. I was nice learning.

  33. Looks like you are a specialist on this because you just made it so easy to be with you, motivated me to learn more on the subject! May I ask you, do you devote a lot of effort to it because you seem to be so in tune with Medical Assistant

  34. Hi, Anyway how to protect the pages on wordpress? please help me i like your ideas on how to show intro password on protected post.

    Please help me to solve my problem regarding page with protected username and password.

    MM

  35. I want to thank you for the efforts you write in this post. I hope the same best work from you in the future. Thanks for sharing us a great information that is actually helpful. Good day! bachelors degree fire science

  36. Brand Yourself and Advertise any site all with one URL Free to Join masters in social work online

  37. I want to be a part of this mags. I have idea to make a good design and to make a good layout for this mags. We need to make other people to feel interesting by see our mags cover, then they will buy it bachelor in criminal justice

  38. 51
    sun

    My 2 year old son has been in the hospital for bilateral pleural chylous effusions since Jan 29, p/o Fontan in November of 2009. He has tried diet, diuretics, thoracic duct ligation and now pleurodesis on the right side. Marleen Humbel

  39. please read through the comments because most common issues have already been discussed many times. Thanks.
    masters educational leadership

  40. please read through the comments because most common issues have already been discussed many times. Thanks. masters in computer information systems

  41. Thanks so much! Great plugin.

    masters of health administration

  42. thanks . very good plugin.

  43. Thanks so much! Great plugin.
    drm removal tool, remove drm protection

  44. 45
    person_guyz

    Before you comment: If you are having an issue with a script, please make sure you have read the entire article. Also, please read through the comments because most common issues have already been discussed many times. Thanks.
    rn bsn online

  45. 44
    person_guyz

    hey, i don’t know how to use the file and everything. i tried putting it into the url and it doesn’t show me the page. could you email me soon? thanks for your help! (:
    nursing informatics

  46. One of the best articles I’ve read in this subject. Thank you !
    cookies by the dozen

  47. 42
    jibran

    Companies these days are using ergonomic furniture to ensure that there are no injuries from work related hazards. Use an ergonomic chair and feel better comfort in your back and shoulder. översättning

  48. this is awesome. just what I have been looking for for ages! I’m going to have a go at donating to you (although last few times i’ve tried it doesn’t work as I am in China but from England so the donate process make my bank think I’m a fraudster..I will have a go though) thanks again! really hope you keep supporting this plugin… :)

  49. And if you download the right software, you can burn MP4 to DVD. How to remove DRM protection from M4V, WMV, M4P, AAC, M4A, WMA, OGG, iTunes, Napster, Rhapsody legally? So that you can burn iTunes to DVD or convert DRM files to other unprotected formats.MOV to DVD, DRM Removal Tool, MP4 to DVD

  50. Big idea …
    Thank you for this post.

  51. 38
    Nick

    hey, i don’t know how to use the file and everything. i tried putting it into the url and it doesn’t show me the page. could you email me soon? thanks for your help! (:

  52. 37
    Mari

    i’m confused, what’s this file we’re supposed to open? i’ve tried adding the /wp-includes/post-template.php to the url but that doesn’t work. could you drop me an email at russmsoh@gmail.com please? thanks! :)

    not a very good computer person if you haven’t noticed. :D

  53. We supply all kinds of moncler boots,moncler bags,moncler coats,moncler jackets,moncler T-shirt,moncler vest and so on.We have got a good reputation pf our products with top quality and good price.We sincerely look forward to futher cooperation with you for mutual benefits.We are sure that you will find working with us is a pleasant, time-saving and profitable experience. Please feel free to contact us if you have any questions.Our website is http://www.newlyapparel.com.

  54. thank u so much!

  55. I am able to get it to work with WP 2.92, please send me an email or leave your email I can send you the modified file.

  56. Is there a way to do this in WP 2.9.x? I just tried and couldn’t find the file containing that bit of code. I would love to get this working.

    Thanks.

  57. Great post, will do this asap. Thank you for the tip.

    Regards,
    Peter Trape

  58. I’ve tried the combinations above and ended up with this
    $returns = mysql_query($query);
    $result = mysql_fetch_row($returns);
    $post_title = $result[5];
    $post_excerpt = $result[7];
    It worked for a while and now it only displays the title twice :(
    Any help please?
    Andrew

  59. We have updated the “better-protected-pages” plugin to V1.1 (available from wordpress.org) which works even better and allows you to show an excerpt before the improved password area. The best thing is that there is also a “Re-lock” button added, which allows you to lock the page again when you have finished reading it.

  60. Sorry just missed to put the “;”

    
    $output = $post->post_excerpt;
    

  61. There is a better way to custom this and be able to show your custom excerpt of your post.

    On Wordpress 2.8.3 I did this
    Update then your post-template

    Original code

    
    function get_the_excerpt($deprecated = '') {
    	global $post;
    	$output = '';
    	$output = $post->post_excerpt;
    	if ( post_password_required($post) ) {
    		$output = __('There is no excerpt because this is a protected post.');
    		return $output;
    

    You have to change the following line :

    
    $output = __('There is no excerpt because this is a protected post.');
    

    by

    
    $output = $post->post_excerpt
    

    I did it and it’s working great ;)

  62. Hi Everyone,

    Just wanted to say that I have just created a plugin which does this… and more! You can get it from my website, or direct from the wordpress plugins section – search for “better-protected-pages”

    Hope you like it.

    Tim

  63. 26
    lenny

    A tutorial or some help would be nice. I’m not sure where or how to use this “/wp-includes/post-template.php” any help would be appreciated.

  64. Is it possible to show different content if you do not have the password entered, and if you enter the password, you get totally, different content?

  65. This code has been tested, and works, with the latest WordPress release – 2.8

  66. useful hack trick, thanks.

    BTW, can I use this hack on blogs hosted on wordpress.com?

  67. it will display the content you have before the ‘more’ tag …

    what hack do you do to display ‘an excerpt’ of the first 30 words?

  68. This code modification has been tested in the latest release of WordPress (2.7.1)

  69. Thank you for this trick !!
    I’ve used it on a Wp 2.7 blog, and it works!
    Bye,
    Massimo

  70. 19
    whoopeedo

    Hey there,

    Instructions

    For WordPress 2.0 or 2.1, open /wp-includes/template-functions-post.php

    For WordPress 2.2 or 2.3, open /wp-includes/post-template.php

    it says to open those templates, I’m sorry but I’m an ameteur at this, how do I open them ?

  71. 18
    Willy

    Is this hack still works with release 2.7 Wordpress? THanks

  72. 17
    capdase

    how can i make it work? :( (

  73. Wonderful hack! I’m using it. Thank you.

  74. Works perfectly, great tutorial. Much help.

  75. I added a solution for this to the WordPress forums. It uses the same basic approach as jam (comment #13), but it replaces the message with the post’s excerpt. This also solves the issue raised by jalansutera (comment #1) and it does work on pages (comment #10).

    http://wordpress.org/support/topic/169520

  76. This is a much better solutions, without breaking in to core code:

    function change($title)
    {
    $vardi= array(“Å is raksts ir aizsargāts ar paroli. Lai to lasÄ«tu, lÅ«dzu ievadiet paroli:”, “Protected with password”);

    return str_replace($vardi,’LÅ«dzu, ievadiet paroli, lai Å¡o sadaļu apskatÄ«tu!’, $title);
    }

    add_filter(‘the_content’,'change’);

    if (have_posts()) : ?>

  77. 12
    mellow

    hi, i’m using wordpress 2.3.2 and I can’t seem to find this:

    $output = get_the_password_form();
    return $output;

    Please advise, thanks!

  78. Notice: The instructions above have been tested with WordPress 2.3, and the same method works. The documentation has been updated to reflect this.

    Michael: Yes, it will work for pages – I just tested it.

  79. Hi there,

    Nice code you got here. Everything above is about having a intro before password in Post.
    I was wondering if the same will work for Pages. I would like to have a intro on my page followed by the password box.

    I am WP 2.2, so hope you can help.

    Thanks

    Michael

  80. you’re amazing!!!! (:

  81. Wesley: Thanks, fixing now.

  82. Everything work except that you reversed the file names.

    For WordPress 2.0, open /wp-includes/template-functions-post.php

    For WordPress 2.2, open /wp-includes/post-template.php

    Again thanks for the hack.

  83. Wesley: I took a look at the files, and the instructions are the same for WordPress 2.2

    The only difference is the file you edit – which is listed above.

  84. 5
    Wesley

    Thanks, I am looking forward to your instruction for the 2.2

  85. Wesley: Since the template-functions-post.php file does not even exist in WP 2.1, no. I plan to eventually post updated instructions for 2.1 though.

  86. Is this mod work with the current release WP 2.2.1?

    thanks

    Wesley

  87. jalansutera: Unfortunately not. I have not done much work with modifications to the feed generation system yet.

  88. Hi.. I like your hack. I have put it on my blog too.

    However, the feed of the protected entry shows ” There is no excerpt because this is a protected post”. Do you know how to make the excerpt of the post appears? Do you know how to do it?

    Please help…

Leave a Comment

Before you comment: If you are having an issue with a script, please make sure you have read the entire article. Also, please read through the comments because most common issues have already been discussed many times. Thanks.


Be sure to wrap all code in <code></code> tags.