Created
September 21, 2012 02:44
-
-
Save trepmal/3759471 to your computer and use it in GitHub Desktop.
[WordPress] Referer for password protected posts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
On an archive-type page, password-protected posts can be odd. | |
If the post is near the bottom, hitting submit reloads the page | |
taking you back to the top. This will simply change the referer | |
so that you are brought back to the post after clicking the | |
submit button on the password form. | |
*/ | |
add_filter('the_password_form', 'the_password_form_referer'); | |
function the_password_form_referer( $form ) { | |
global $post; | |
$ref = is_single() ? '' : "<input type='hidden' name='_wp_http_referer' value='{$_SERVER[REQUEST_URI]}#post-{$post->ID}' />"; | |
$output = str_replace('</form>', $ref .'</form>', $form ); | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment