I use the native WordPress function get_template_part to pull in different php files I’ve added to my theme:
http://codex.wordpress.org/Function_Reference/get_template_part
That helped! Thanks! Here’s what I did. First I had to create a page called contact-password.php in my theme. If you don’t have ftp access to a site to just make that file in your theme, you can plug this code into line one of the header.
<?php touch('wp-content/themes/your-themes-name/contact-password.php');?>
save the file, load the main page once, and then remove this code. The file is automatically added to your editor.
Here’s the functions.php code:
<?php
add_filter( 'the_password_form', 'custom_password_form' );
function custom_password_form() {
global $post;
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
$o = '<form class="protected-post-form" action="' . get_option('siteurl') . '/wp-pass.php" method="post">
' . get_template_part( 'contact', 'password' ) . '
<label for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" />
</form>
';
return $o;
}
?>
It pulls in whatever you place on contact-password.php to the password protected pages.
Hi, I used this great trick but now my password box and submit buttons aren’t appearing properly. The submit button is before the password input box. See it here: http://wtsglobal.com/wp/services-agreement/
Would love any suggestions. I’m not so much a coder….
It looks like a styling issue to me. on style.css I took off
float: left;
under input[type=”submit”], input[type=”reset”]
and it looked fine.
You may have to give this one button on the private page a class of its own to make it look right.
okay, I managed to get a line break in so it looks ok, but Firefox is prepopulating the password field with something… Looks fine in chrome and safari…
Under Firefox > Preferences > Security, i have the box checked to remember passwords for sites. You probably have this too. Just uncheck that and clear your browser’s cache. The pre-fill you see in the password input should be gone.
Thanks the style thing works better than my line break. Any thoughts on the password being ghost prepopulated in Firefox?
I figured it out. I added autocomplete=”off” to the password input field in the code. Thanks for the quick responses! Client happy.