The problem is that WP will redirect to the referrer when the authentication succeeds.
Fortunately, you can also supply _wp_http_referer and it will be preferred over the HTTP Referrer, so we need to add a hidden field to the form and fill it with the permalink of the post in question:
echo str_replace('</form>', '<input type="hidden" name="_wp_http_referer" value="' . esc_attr(get_permalink(123)) . '" /></form>', get_the_password_form(123));
with 123 being the post ID.
Related Posts:
- Creating my own Admin Forms in a WordPress CMS?
- how to redirect to a custom password retrieval page
- Custom protected password page with ACF
- Intercept invalid email during lost_password
- How do I remove the eye icon that shows visibility on login screen and reset password screen
- Using transients to store captchas
- Add Div to Comment Form
- Adding custom field in all widgets, but at the top of the form, in admin area
- Custom search to display results within same page
- How Can I Move Data From Form 1 To Form 2
- Deep customization of wp-login.php
- Lost password empty field error redirect to custom login
- Custom Log In Screen – Disable password recovery [duplicate]
- Saving contact form 7 data into custom Table
- Woocommerce custom checkout form
- Custom login and registration forms
- Custom Form not generating URL
- How do I make Dynamic Student Admission Form?
- How to create multipage form and redirect to specific URL based on inpput?
- No plugin populate user information in to form
- How do I add a dropdown menu to a form?
- Password Protection issue
- Custom password set/reset link in same URL format as default does’t work
- How to automatically pull an information from a form field onto an other page?
- How to submit form data in the same page in WordPress without reloading the page?
- How to Password Protect whole site except for some subdirectories
- Custom dropdown search form that allows users to select option B based from Option 1
- Accountless password generation
- How to get name and email value from a custom form and add it to campaign monitor subscriber list?
- Custom user fields validation on registration
- Two searchforms with different categories/posts per page
- add unique code required to register
- Page template with custom html fields inside a content
- Why do I get the timeout warning?
- Backup the Database and Restore from the Backup?
- Scaling a WP eCommerce site
- Looking for a lightweight theme using WP3 new tags and features (not 2010) [closed]
- What is the best way to customise admin files so they survive future upgrades?
- Verify nonce in REST API?
- Add custom html to last sub-menu item
- Limit Media Library to Given Folder
- How can I get posts in a subcategory to display on it’s parent categories archive page?
- Custom taxonomy: same terms, but for different years
- customize_register with Multiple controls/settings – how to get values?
- Best practices for A/B testing?
- Editing the Number at the end of Page URLs / Editing Page Slugs
- Automatic image renaming based on title
- Integrating the WordPress admin panel with a frontend theme
- simple wp_insert_post example
- Redirect members to custom page upon logging in through WP admin
- Can I use $wpdb for my custom tables in the WordPress database?
- How to get input_attrs in the sanitize function?
- Php custom query function assistance
- Integrating MailChimp newsletters as post
- How can I manage my multiple wordpress websites from main website?
- What is WordPress file encoding?
- Change from /wp-admin/ to something else?
- WP_Query with the “offset” argument
- Adding “Interesting Tags” & “Ignored Tags” like StackOverflow.com in a WordPress Blog?
- Auto add taxonomy if post has category
- Add a containing DIV to core Gutenberg blocks
- Allow comments without approval for custom content type
- Add ‘Right Now’ widget to custom dashboard
- Are there any security issues with setting the WP_INSTALLING constant to true?
- Naming script handles right way
- How to add classes in the wp_list_category parent link
- How do I embed a Javascript form directly into a page?
- How to edit pages after installing WP
- Exclude custom taxonomy tag from loop
- User Roles Not Sticking
- Login form in popup
- Replace “WordPress” word in title of Dashboard
- Multiple WordPress outside wordPress installation?
- Create default_content layout template based on post id
- Remove ability to Permanently delete an image from the Media Library
- Filter posts by custom taxonomy terms
- shortcodes – style them or change/remove the square brackets?
- Dynamic title in WordPress homepage
- Adding a login form that concatenates three fields into a username
- Moving from development while pulling production database without overwriting, to production
- Ability to only view (not edit) other user’s personal profile information
- Fastest way to get the comment and ping total count for a post
- want to create a subcategory.php to manage subcats
- Updates for a private theme
- Hi, I wanted to make custom search with multiple fields
- Is it possible to add a ribbon in the background of h1 on every page?
- How to add textarea field to taxonomy (tag)?
- Contact From 7 Custom Validation Issues
- How to add an extra button on woocommerce shop page and use it to send the product info with image in a mail? [closed]
- changing font size and font of a custom message added after comment
- education system [closed]
- Search widget will search everything in the site, how to limit to only search gallery name
- Custom wp-content and upload directory
- A form that can save/edit after first input
- custom post type – page template
- How to add custom control to a page?
- Navigation label for page in custom theme
- Custom comments list, right depth
- Order posts with a custom field but also without
- How to hook up search results page to a back-end page?