Skip to content

Instantly share code, notes, and snippets.

@trepmal
Created September 21, 2012 02:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trepmal/3759471 to your computer and use it in GitHub Desktop.
Save trepmal/3759471 to your computer and use it in GitHub Desktop.
[WordPress] Referer for password protected posts
<?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