WordPress.org

Ready to get started?Download WordPress

Forums

Change text on protected post (12 posts)

  1. johnyw
    Member
    Posted 1 year ago #

    Hello,

    Can anybody please tell me where I can change the text: " This post is password protected. To view it please enter your password below:" ?

    I want to add a line that visitors tell how to obtain a password.

    Thanks

  2. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    Try something like this in your theme's functions.php file:

    // Amend post password form
    if( !function_exists ('my_password_form') ) :
    function my_password_form() {
    	global $post;
    	$label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
    	$output = '<div class="password-form">
    	<p class="protected-text">' . __('This post is password protected. To view it, please enter your password below:'') . '</p>
    	<form action="' . get_option('siteurl') . '/wp-pass.php" method="post">
    	<p><label for="' . $label . '">' . __('Password:') . ' </label> <input name="post_password" id="' . $label . '" type="password" size="20" /> <input type="submit" name="Submit" value="' . esc_attr__('Submit') . '" /></p></form></div>';
    	return $output;
    }
    endif;
    add_filter('the_password_form','my_password_form');
  3. johnyw
    Member
    Posted 1 year ago #

    Well, I pasted this to the end of the functions.php file and I got:

    Parse error: syntax error, unexpected T_FUNCTION, expecting T_STRING or T_VARIABLE or '$' in /home/jeeweepi/domains/jeeweepix.be/public_html/wp-content/themes/twentyeleven/functions.php on line 613

  4. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    And what is on line 613?

  5. johnyw
    Member
    Posted 1 year ago #

    Well, I had to redo it,

    Now it says line 618:
    <p class="protected-text">' . __('This post is password protected. To view it, please enter your password below:'') . '</p>

  6. johnyw
    Member
    Posted 1 year ago #

    Not possible to adjust that ?

  7. converting2wp
    Member
    Posted 1 year ago #

    Esmi's solution does seem to have a syntax error (mismatched quotes?), but when I made those corrections it still didn't work.

    It appears that a recent change to WordPress broke that solution -- at least according to the Codex article on Using Password Protection and my tests on WP 3.5-alpha-21466 (sorry, but I haven't reset my test environment to 3.4.1).

    A different solution from the forums, does seem to work:

    function custom_password_form($form) {
      $subs = array(
        '#<p>This post is password protected. To view it please enter your password below:</p>#' => '<p>This is the new message.</p>'
      );
    
      echo preg_replace(array_keys($subs), array_values($subs), $form);
    }
    add_filter('the_password_form', 'custom_password_form');

    Ref: http://wordpress.org/support/topic/password-protect-this-post-change-text?replies=6 While it's for WP 2.6 from four years ago and so may not be using the most recent features, it seems simple enough and the post shows examples of how to add CSS to the form elements.

  8. johnyw
    Member
    Posted 1 year ago #

    Thanks converting2wp, seems to work, but the funny thing is that everything ( the changed text and the password field and the submit button) is also appearing on the top left of my blog ???

    Can you please advice me how I can solve this ?
    Thanks a lot,

  9. converting2wp
    Member
    Posted 1 year ago #

    You'll need to post a link to the page you're talking about for us to have any chance of helping. In my test, the password form appeared where I'd expect to see it.

  10. johnyw
    Member
    Posted 1 year ago #

    Sorry, it's here

  11. converting2wp
    Member
    Posted 1 year ago #

    Try changing the "echo" above to "return". [I just copied the code from the referenced incident and "echo" worked for me where I'm also using twentyeleven -- but "return" also works and may prevent the extra form from showing up in your example.]

  12. johnyw
    Member
    Posted 1 year ago #

    That solved the problem , thanks

Topic Closed

This topic has been closed to new replies.

About this Topic