Sequence comparison between template_redirect
and login_redirect
According to the loading sequence. By default, after login, WordPress redirect the user to a specific page in order to get the cookie working which I have answered here before.
Login -> Redirect -> Template Redirect(canonical) which is normally done by redirect_canonical() if slug does not found, go to 404, if using /?p=111, check if permalink is in used, if so, direct to permalink structured url and so on
If using template_redirect
, it means the page is being handled in template-loader.php
. It becomes
Login -> Redirect -> Template Redirect(canonical) -> Custom Template Redirect
Because it follows do_action( 'template_redirect' ) in template loader which will load multiple times in this case. One way to optimize the script is that using a higher priority for the custom template_include
hook so that it check and redirect earlier functioning similar to Login Redirect.
Since reaching template_redirect
is a bit late of loading time. So it is still not an ideal place to do a user login checking and redirect to somewhere which is not template related matters.
So, unless necessary such as doing rewrite, custom URL structure or custom template preparation. Using it in later time is not recommended. Also, if redirect is handling unskilfully, it might also affect the SEO ranking. That's based on the actual loading sequence, SEO optimisation point of view and personal experience.