Give this a try…
function save_url_before_login() {
if(!is_user_logged_in()) {
$_SESSION['referer_url'] = get_the_permalink();
}
add_action('wp', 'save_url_before_login');
and:
function redirect_after_login() {
$redirect_url = home_url("https://wordpress.stackexchange.com/");
if (isset($_SESSION['referer_url'])) {
$redirect_url = $_SESSION['referer_url'];
unset($_SESSION['referer_url']);
}
return $redirect_url;
}
add_filter('login_redirect', 'redirect_after_login');
Related Posts:
- WordPress plugin from own server
- How to avoid plugin name conflicts from the upgrade notifier?
- Remove WordPress Toolbar buttons
- WP showing “warning: call_user_func_array()”, What to do?
- How can I dequeue a Plugin Stylesheet?
- Can a plugin cause permanent damage?
- Adding an admin page – OOP approach not working
- How can I pass a variable to wp_ajax action?
- Declare a function before plugin does on the theme functions.php file
- Moving image attachment from post to another?
- How to call a function in wordpress plugin from another site
- Activate Plugin which is in subfolder?
- Under which circumstances is the .maintenance file not deleted?
- Autoload via composer in plugin interference
- How can i change an image’s author?
- WordPress plugin form not saving data
- NextGen Gallery – automatically create gallery sub page?
- How do I make images clickable so as to enlarge them using lightbox?
- WP Job Manager Category Drop-down; Change Placeholder Text Via Filter
- FacetWP group listings by custom field [closed]
- Plugin Paths Issue
- UnInstallation of a Plugin from a developers perspective – The correct and clean method
- Change wordpress current_time function to different timezone
- Load custom PHP on a custom URL via a plugin
- Remove Duplicator plugin from admin menu if not an administrator
- Plugin for a text modal box [closed]
- Restrict media upload size by format
- Creating custom HTML pages
- How to display the “ratingValue” and “ratingCount” values generated by the KK Star Ratings plugin into my page’s recipe ld+json schema
- Two problems on my WordPress installation [closed]
- Frontent user submit and view content [closed]
- Center and hide overflow of WP toolbar custom links
- options creation for plugins
- Users are being redirected to main site when trying to register on subsite of my Multisite network
- Remove .htaccess portion upon plugin deactivation?
- Two plugins using the_title; one not passing second param.
- First plugin, problem with get_pages
- eLearning Module
- Are there action hooks for comments?
- Collecting email addresses via a “beta” sign up form
- Export postmeta (custom fields)
- Customizing a blog page layout
- Sub Plugin deactivation when Parent Plugin deactivate
- what is the point of telling add_filter how many parameters you want passed to the function?
- I would like to remove date display on photo preview
- Developing a WordPress plugin like a component in Joomla
- Google Maps with categories
- Somehow adding to “Insert Into URL” posts are contradicting each other
- Add posts from other WordPress blog to the current one
- How to create repeater field manually, without plugin (ACF Pro)?
- Should I use the action in the plugin’s main file?
- Woocommerce checkout page broken when set as a checkout in woocommerce settings [closed]
- Unknown theme modal source
- German Market: How can I only show the imprint in the footer of the mail? [closed]
- How can replace this url
- Plugin Update History
- Display Multiple Photos as Featured Image when mouse moves on to it post
- How to overwrite a plugin?
- How can I implement radio buttons with icons in Contact form 7?
- Issue Saving Posts That Contain Shortcode
- SimpleXML is not working with xml response from external api
- SEO Site Title appearing in google search despite not being added
- Use action, filter, or hook to append HTML to WordPress plugin function
- How to use get_blogs_of_user?
- Custom wp_list_tables redirect on specfic page
- On button click, redirect users to registration page instead of another page
- Create API for registering user on wordpress site with 3rd party site
- Hook to display element as product on category page
- No result after wpdb->insert
- I can’t use WP_Query
- Fatal error: Out of memory with the Duplicator plugin
- Fetching users data from REST API
- Automatically check “Enable stock management at product level” to the existing products?
- Why user profile update creates Additional Capabilities
- WP Plugin: Print javascript in header
- Adding list of Indexes in wordpress document
- API calls on plugin activation or init?
- Category archive in menu
- WordPress filter function using query modifications
- Trying to override/intercept a PhotoMosaic gallery link in WordPress using jQuery
- How can I Customize My WordPress Admin Dashboard into Dark Mode?
- Add custom fields in the new and edit the site forms without touching the WP core
- Plugin use of ajax/jquery depending dropdown
- Extend WordPress REST API with Scheme Pro Plugin
- How to submit the custom form data in database in WordPress without plugin?
- Plugin problem. Question is not appearing.
- Create Landing Page With Login or Subscribe Form [duplicate]
- Filter orders by product in admin
- Sorting/Ordering Poll Plugin?
- Get URL for featured image for posts? [closed]
- Windows 10 Printer that Sends to WordPress [closed]
- Option value not getting updated until page refresh in WordPress
- How to create an Info Box on WordPress [closed]
- Fatal error: Uncaught Error: Call to a member function fetch_array() on bool
- Use inline callable for hooks and filters
- Error in using ‘admin_enqueue_scripts’ action through a class
- Edit a page/post DB data?
- how to update WordPress plugins from external website with nodejs?
- this code is fiven by chat-gtp but nothing match even I key in the value of a cell. help!
- How do i fix this error?