• 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

Viewing 11 replies - 1 through 11 (of 11 total)
  • 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');

    Thread Starter johny willemyns

    (@johnyw)

    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

    And what is on line 613?

    Thread Starter johny willemyns

    (@johnyw)

    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>

    Thread Starter johny willemyns

    (@johnyw)

    Not possible to adjust that ?

    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: https://www.ads-software.com/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.

    Thread Starter johny willemyns

    (@johnyw)

    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,

    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.

    Thread Starter johny willemyns

    (@johnyw)

    Sorry, it’s here

    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.]

    Thread Starter johny willemyns

    (@johnyw)

    That solved the problem , thanks

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Change text on protected post’ is closed to new replies.