Firing a function AFTER redirect

I am using a function that redirects the user to a custom page, rather than wp-login in the event of errors. In my case I am using the Http Referer function to send the user back to the same page because I have the login form in a modal. How can I execute a function on the redirected page, so that the page automatically opens the modal? This is the code for the redirect in the event of an error: …
Category: Web

if is_page() is not working with wp_redirect

I have a plugin installed, which is creating user profiles on frontend. The ID of this page is 301 in backend of wordpress. If a profile site is visited, i want to append the url with a parameter. The parameter value is stored in a cookie. The code for appending the URL is working, but when i add the code to only show on this page id its not working. The code is executed in my child themes functions.php NOT …
Category: Web

Use Parent Pages for URL Structure without Landing Page

So this is more a philosophical question than anything, and if I'm asking this in the wrong place, I'm happy to remove the post: What's the best way to use a parent page for structure while keeping that page inaccessible to users? I'm running into two issues: First, I want to use the parent page in the main menu so that I can take advantage of WordPress's current-menu-parent and like classes for styling purposes. I know that normally you can …
Category: Web

wp_redirect() - headers already sent

I am trying to use wp_redirect() to redirect the user after successfully submitting a signup form on the page. It's not working and shows the following error: Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/theme/wp-content/themes/test/header.php:10) in /Applications/MAMP/htdocs/theme/wp-includes/pluggable.php on line 1178 I understand there has been already output before, that's why it's not working, but I have no clue how to make this work. The signup form gets rendered by a function, and is submitted …
Category: Web

redirect does not work in ajax function

I'm using ajax to post the form data. In the end I want to redirect to homepage. I'm trying following code, it does not work. It returns error 302. How can I redirect in the following function? Thanks. add_action('wp_ajax_nopriv_custom_register', 'custom_register'); add_action('wp_ajax_custom_register', 'custom_register'); function custom_register(){ //process wp_redirect( home_url() ); exit; }
Category: Web

Trying to re-direct users to specific page based on an ACF variable

I have a case where I have an ACF variable that is stored within a users profile and based on that variables state I need to redirect to one of two pages once the user logs in. This is just a true or false value that will represent if a user has logged in before. I have tried using wp_redirect to do this and it does sort of work but seems to run excruciatingly slow and sometimes will briefly get …
Category: Web

WP didn't redirect to canonical category URL

I have a problem with canonical redirect. mydomain.com/mycat is the correct category URL but the following URL works too: - mydomain.com/asdfa/mycat - mydomain.com/1234/mycat - mydomain.com/anythingyouwant/mycat And all these URLs show the category mycat... The canonical is mydomain.com/mycat and now Google give results with bad URLs. Can you please help me because I didn't understand why. I have the same template on other website and when we try to go to mydomain.com/asdfa/mycat, WP redirect to the canonical URL mydomain.com/mycat
Category: Web

Using wp_login vs login_redirect to redirect based on user-meta

I wrote a function to redirect first-time users using login_redirect, and it was working great. Then I changed the hook to wp_login (to get it to play well with a social login plugin), and now the function is redirecting all users who sign in via the wp_login_form. PS: the redirect works fine when logging in via my social login plugin. Is there a difference between wp_login and login_redirect, or is something wrong with the conditional php? Here's the code: //Hook …
Category: Web

Unable to get wp_redirect() working after adding a CPT via the front end

I am attempting to learn PHP by creating a relatively simple application built on wordpress, it is a basic CRM and I've made decent progress but have been stuck on some of the finer points. I've been having some serious 'headers already sent' problems with getting wp_redirect() working after a user creates a new customer. Here is an example of what I want to do: /new-customer.php : Create a new Custom Post Type via the front end and then redirect …
Category: Web

How can I prevent caching of wp_redirect?

I am working on a multisite install where one specific site needs to have access restricted to only users who are logged in AND have a specific user meta set (key="cr_access", val="Yes"). If the user is not logged in, or that meta key is not set to "Yes", then they should be redirected to the specified url. The redirect works properly, however it seems to be getting cached. If a user tries to visit a page before logging in, then …
Category: Web

Login to wp-admin "redirect_to" points to wrong URL after migration

I have a WordPress site hosted on GoDaddy, it's a Windows server, (i have the web.config set up). and .htaccess correctly configured. The site was working on example.com/wordpress , as it was a development test. I moved the site to example.com . I changed the site url and wordpress URL to example.com on the database through PhpMyAdmin, and updated the permalink structure. I also updated all the wp_post 'content' field to change the URL's. Issue When I try to Log …
Category: Web

Check If Taxonomy A and Taxonomy B has same Slug, 301 Auto Redirect Tax A to Tax B if True in Wordpress

Please How do I achieve this? I have WordPress Default Taxonomy - Tag and a custom Taxonomy - Artist. I want to check for TAGS that have the same slug as ARTIST and 301 redirect it to the ARTIST. Example Check If: website.com/tag/drake and website.com/artist/drake have the same slug which is true. then Automatically 301 Redirect: website.com/tag/drake to website.com/artist/drake If the slug is not the same, then do nothing. I found this Answer but it's not exactly what I need …
Category: Web

Why sometimes wp_redirect() reset cookie?

I've been trying to set cookie to mark users that get redirected before checking out because of incompleted profile. The problem is when wp_redirect is executing and new page is opened, the set cookie dissapears. Here's my code: add_action('woocommerce_before_checkout_form',function(){ if (is_user_logged_in()){ $user = wp_get_current_user(); if ( bpprocn_has_incomplete_profile($user->id) ) { setcookie('wsk_redirected_from_cart',true,time()+3600); wp_redirect(bp_core_get_user_domain( $user->id ) . bp_get_profile_slug() . '/edit/group/2'); exit; } } }); And you can see how the cookie was set for just a short while and disappears after the new …
Category: Web

wp_redirect is not working sometimes

I've tested the following code in my function.php: if ( $_GET['test'] ) { wp_redirect('https://google.com'); } and it works, if I go to https://example.com/?test=true, I will be redirected to Google. But I found out when I put wp_redirect() in a function hooked to some action, it won't work. Instead after its execution users will stay on the same page, and, in my case, some CSS files seems not being loaded. Since I haven't figured out what kind of actions will trigger …
Category: Web

Redirect to /404/

Is there a way I can redirect the URL slug of the 404 template to /404/ so so for example if I have /category/media/blah it redirects to /404/ Is that possible I don't know if it can be done using .htaccess. Ronny
Category: Web

How to after saving or publishing a post redirect back to the original page

When viewing a list of posts on the admin page wp-admin/edit.php I click on edit. I then finish editing the post, click on save or publish and expect to be returned to the original admin listing page I started on. The same with when I'm viewing the front end of a post and click the edit link in the admin toolbar. After I finish editing the post I want to be returned to the original screen I was on. To …
Category: Web

How to disable Uncategorized category URL?

I would like to disable the Uncategorized public URL (i.e. /category/uncategorized), since I'm not using post categories and already have the posts list with pagination on the main Blog posts page. Having the Uncategorized category URLs simply creates duplicate pages. Is there a way to disable post categories entirely until I'm ready to use them? It seems WordPress forces posts to be associated to a category. In lieu of this, is it a good practice to simply redirect the uncategorized …
Category: Web

How to redirect one admin URL to another when admin page URL has "/admin.php?page=" in it?

The following code (from here, middle section chopped out) allows me to redirect users who land on a certain page in the WP admin to another admin page... function admin_redirects() { global $pagenow; /* Redirect Customizer to Theme options */ if($pagenow == 'customize.php'){ wp_redirect(admin_url('/admin.php?page=theme_options', 'http'), 301); exit; } } add_action('admin_init', 'admin_redirects'); It works great...for some pages. The problem is I cannot get redirects to work for pages originating with a URL structure such as "admin.php?page=example-options." The example-options string is just …
Category: Web

Redirect after scrolling the page

is it possible to create a redirect only after the page has been scrooled, for example, in the middle and redirects to another page? I tried various solutions and plugins but couldn't find anything that suited me
Category: Web

Save current post using custom save button

I want to display a custom button in my "Edit post" screen which saves the current post (everything including custom fields) and then runs a function (in my case redirecting to another page). I know how to redirect after saving the post using the save_posts action and wp_redirect but I can't figure out how to save the post when a custom button is clicked. This is my function for redirecting using save_post (which doesn't work for me since I need …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.