{"id":18811,"date":"2021-01-16T17:00:25","date_gmt":"2021-01-16T16:00:25","guid":{"rendered":"https:\/\/qodeinteractive.com\/magazine\/?p=18811"},"modified":"2022-05-05T11:59:44","modified_gmt":"2022-05-05T09:59:44","slug":"wordpress-redirect-after-login","status":"publish","type":"post","link":"https:\/\/qodeinteractive.com\/magazine\/wordpress-redirect-after-login\/","title":{"rendered":"How to Redirect Users after Login in WordPress"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><p>[vc_row][vc_column][vc_column_text]If you ever logged into an eCommerce or membership website, you may have noticed that after you log in, you are redirected to some website-specific page. This is because some webmasters choose to redirect their users after they log in to the website. Even though it might seem strange at first, this feature, which was introduced in WordPress 3.0, is very useful and constantly gaining in popularity.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]In this article, we will cover how to use WordPress to redirect users after login, as well as examine the reasons why you should do so. By carefully studying the situations when login redirection is used, we hope to convince you of the usefulness of this feature, and inspire you to try it out yourself. With that being said, let us proceed.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;68px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\">Reasons for redirecting users after login in WordPress<\/h2>\n<p>[\/vc_column_text][vc_column_text]After logging in to a WordPress website, users are, by default, redirected to the admin dashboard. However, there are many situations in which you might want to use custom redirections after the user logs in. This, of course, is based on the specific user, his <a href=\"https:\/\/qodeinteractive.com\/magazine\/wordpress-user-roles\/\">user role<\/a>, or some other factor relevant to your site. Let us explore some of those situations and the reasons for redirecting users.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]The most obvious reason for WordPress redirect after login is to streamline the user experience on the website, especially if this is their first time logging in. If your website has a lot of subscribers or customers, allowing them to access the WordPress dashboard first might leave them clueless as to what their next step should be. Instead, it would be better to, for example, redirect customers to a shop page and subscribers to an announcement page.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Additionally, you can choose to redirect some of your users, after login, to your premium or member-only content. This feature is useful for websites in various niches, but especially for membership communities or educational websites. Furthermore, you could even make different tiers of access to your premium content based on the given user role or even on a specific user.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Finally, you can use the WordPress redirect after login to allow only a handful of authorized users to edit your existing content. At the same time, this would disallow content editing for any other unauthorized user. Instead, all such users would be redirected to alternative dashboard pages, based on their user role and capabilities. This is particularly useful for listing websites, for example.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Apart from redirections after login, you can implement various <a href=\"https:\/\/qodeinteractive.com\/magazine\/how-to-create-301-redirects-in-wordpress\/\">other kinds of redirections in WordPress<\/a>. We will mention some of them, like redirections on logging out of the website, but our focus will stay on the redirections after login.[\/vc_column_text][vc_empty_space height=&#8221;80px&#8221;][vc_widget_sidebar sidebar_id=&#8221;new-top-picks-banner&#8221;][vc_empty_space height=&#8221;81px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\">How to redirect users after login in WordPress<\/h2>\n<p>[\/vc_column_text][vc_column_text]As with most new features that you could add to your WordPress website, redirecting users can be accomplished either with the use of plugins or through custom code. It is worth mentioning that, depending on which theme you are using, user redirection after login could be included with the theme. Therefore, it\u2019s a good idea to first explore the features offered by your theme as it might spare you from having to use additional means such as plugins or custom code.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;72px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\">Using a plugin<\/h3>\n<p>[\/vc_column_text][vc_column_text]WordPress plugins are a go-to solution for most WordPress users when looking to add a new feature to their website. Thanks to the abundance of plugins, you are bound to find a suitable one (free or premium) for almost any purpose. As such, we advise browsing <a href=\"https:\/\/wordpress.org\/plugins\/\" target=\"_blank\" rel=\"noopener\">the WordPress plugins repository<\/a> first, which we\u2019ve done as well.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]One of the plugins that we found which enables WordPress redirect after login is <a href=\"https:\/\/wordpress.org\/plugins\/peters-login-redirect\/\" target=\"_blank\" rel=\"noopener\">Peter\u2019s Login Redirect<\/a> plugin. It allows you to implement redirections both after login and logout. We will cover them both, as the steps for enabling them are the same using the plugin options. If you wish to enable redirections only after a user logs in, simply leave the appropriate logout URLs empty.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]To start, you will need to <a href=\"https:\/\/qodeinteractive.com\/magazine\/how-to-install-a-wordpress-plugin\/\">install the plugin<\/a> first. Then, <strong>navigate to Settings &gt; Login\/logout redirects<\/strong>, where you will find all the options for managing redirect rules.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"667\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Plugin-All-Empty.jpg\" class=\"attachment-full size-full\" alt=\"Plugin All Empty\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Plugin-All-Empty.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Plugin-All-Empty-300x207.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Plugin-All-Empty-768x529.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Plugin-All-Empty-620x427.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]As we mentioned, this plugin offers the option to adjust the URLs a user accesses after he logs into the website or logs out of it. There are settings for specific users, user roles or levels, and privileges a user can have. You can also specify the URL users will access after registering to your website or URLs for users that fit certain conditions.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Additionally, this plugin supports custom redirect rules. WordPress users that want to implement custom rules should carefully study the <em>How to extend<\/em> section of the plugin\u2019s official page. In the following paragraphs, we\u2019re going to cover how to use these options.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]If you want to assign a specific URL where a user will be redirected after logging in or after logging out, you can do so from the first section, called <em>Specific users<\/em>. <strong>Using the available dropdown, select the user<\/strong> for whom you wish to specify the redirect URLs. Then <strong>manually insert the after-login URL<\/strong> in the <em>URL<\/em> field. <strong>Then, if you want, you can add the after-logout URL<\/strong> in the <em>Logout URL<\/em> field. When you\u2019re done, <strong>click on the <em>Add username rule<\/em> button<\/strong> below.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"518\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Users.jpg\" class=\"attachment-full size-full\" alt=\"Specific Users\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Users.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Users-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Users-768x411.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Users-620x331.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]Shortly after, you will receive a success message, and the redirect rule that you added will be shown at the top of the section. You will be able to further edit it or delete it, should you need to.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Following the same steps, you can keep adding new rules, as well.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"558\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Users-2.jpg\" class=\"attachment-full size-full\" alt=\"Specific Users\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Users-2.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Users-2-300x173.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Users-2-768x442.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Users-2-620x357.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]Similarly, if you want to add rules concerning after-login and after-logout URLs for various user roles, instead of specific users, you should do so within the <em>Specific roles<\/em> section. The plugin supports the default user roles, as well as any custom roles added by other plugins or themes.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]To add a new rule based on a given user role, <strong>choose the user role<\/strong> from the dropdown of available user roles. Then <strong>insert the appropriate URL(s)<\/strong> and <strong>press the <em>Add role rule<\/em> button<\/strong> below.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"518\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Roles.jpg\" class=\"attachment-full size-full\" alt=\"Specific Roles\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Roles.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Roles-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Roles-768x411.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Roles-620x331.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]After a brief period, the option will be saved and shown at the top of that section. You will be given the option to edit this rule or delete it, same as before. You can, also, add new rules about specific user roles following these same instructions.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"518\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Roles-2.jpg\" class=\"attachment-full size-full\" alt=\"Specific Roles\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Roles-2.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Roles-2-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Roles-2-768x411.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Roles-2-620x331.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]If you want to implement rules concerning user\u2019s permission levels, you can do so within the <em>Specific levels<\/em> section. You can use these rules to set URL(s) for users with a custom capability or to set URL(s) for specific user role groups, as opposed to manually creating a rule for each user role. This option is similar in use to the specific user role option, and they are often used in conjunction.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]To add a rule for user permission levels, <strong>select the permission level<\/strong> from the dropdown,<strong> add the appropriate URLs<\/strong>, and <strong>press the <em>Add level rule<\/em> button<\/strong> below. We have omitted to fill in the <em>Order<\/em> field, but you can insert a value if you wish\u2014the order field accepts numbers starting from 0. Inserting the order will allow you to specify the position in which the given rule will be shown when placed in the list of existing user permission level rules.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"518\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Levels.jpg\" class=\"attachment-full size-full\" alt=\"Specific Levels\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Levels.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Levels-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Levels-768x411.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Levels-620x331.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]The rule will be saved shortly after you press the <em>Add level rule<\/em> button. Same as with the others, you can choose to edit or delete this rule after adding it, or to create new rules by following the instructions given above.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"518\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Levels-2.jpg\" class=\"attachment-full size-full\" alt=\"Specific Levels\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Levels-2.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Levels-2-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Levels-2-768x411.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Specific-Levels-2-620x331.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]Now, let\u2019s take a quick look at the <em>Post-registration<\/em> section. Usually, webmasters choose to redirect their users after logging in to a <em>Welcome<\/em> or <em>Thank you<\/em> page, or send them to a landing page that offers various products or services. Registering to a site is often paired with a small discount for users to provide further incentive.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]To add a post-registration redirect rule, <strong>navigate to the <em>Post-registration<\/em> section, add the redirection URL<\/strong>, and <strong>press the <em>Update<\/em> button<\/strong> below.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"518\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Post-Registration.jpg\" class=\"attachment-full size-full\" alt=\"Post Registration\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Post-Registration.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Post-Registration-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Post-Registration-768x411.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Post-Registration-620x331.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]Unlike the previous section settings, the URL here will simply remain tied to this option after pressing the <em>Update<\/em> button. If you ever wish to edit or delete the post-registration URL, you can do so using the <em>Update<\/em> and <em>Delete<\/em> buttons, respectively.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Finally, you can choose to redirect users that are not covered by any of the previously implemented rules to a specific page using the option found in the <em>All other users<\/em> section. Simply <strong>add the after-login and\/or after-logout URL<\/strong> and <strong>press the <em>Update<\/em> button<\/strong>.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"518\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/All-Other-Users.jpg\" class=\"attachment-full size-full\" alt=\"All Other Users\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/All-Other-Users.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/All-Other-Users-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/All-Other-Users-768x411.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/All-Other-Users-620x331.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]Like the option before it, the URLs will be saved after pressing the <em>Update<\/em> button. If you wish to edit them afterward, you can do so by using either the <em>Update<\/em> or <em>Delete<\/em> button.[\/vc_column_text][vc_empty_space height=&#8221;68px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\">Using custom code<\/h3>\n<p>[\/vc_column_text][vc_column_text]Another way of adding WordPress redirections after login is to do it using custom code. Please note, this method is more inclined towards more experienced WordPress users, or those that simply don\u2019t want to add another WordPress plugin to their site.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]However, the benefit of using custom code is that you can implement the redirections exactly as you want them. Furthermore, depending on the redirections that you wish to set, this can be done quite quickly and easily. Let us explain how.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]For this article, we have created the following code as an example.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function custom_login_redirect( $redirect_to, $request, $user ) {\r\nif ( isset( $user-&gt;roles ) &amp;&amp; is_array( $user-&gt;roles ) ) {\r\nif ( in_array( 'administrator', $user-&gt;roles ) || in_array( 'editor', $user-&gt;roles ) || in_array( 'author', $user-&gt;roles ) ) {\r\n$redirect_to = admin_url();\r\n} else if ( in_array( 'customer', $user-&gt;roles ) || in_array( 'shop_manager', $user-&gt;roles ) ) {\r\n$redirect_to = home_url( '\/shop' );\r\n} else {\r\n$redirect_to = home_url();\r\n}\r\n}\r\nreturn $redirect_to;\r\n}\r\nadd_filter( 'login_redirect', 'custom_login_redirect', 10, 3 );<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<strong>This code represents a function called custom_login_redirect that is \u201chooked\u201d onto the login_redirect filter hook. Its purpose is to change the default URL that is accessed after login for various user roles. First, we are checking whether the logged user has a set user role and if the role is an array. The main part of the code is processed only after passing both checks. Otherwise, the original $redirect_to URL is returned, meaning no custom redirections will be made.<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function my_login_redirect( $redirect_to, $request, $user ) {\r\nif ( isset( $user-&gt;roles ) &amp;&amp; is_array( $user-&gt;roles ) ) {\r\n\/\/ Main part of the code goes here\r\n}\r\nreturn $redirect_to;\r\n}\r\nadd_filter( 'login_redirect', 'my_login_redirect', 10, 3 );<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]In the main code section, there are also a couple of checks that are performed. First, <strong>if the logged-in user is an admin, editor, or author, they will be redirected to the WordPress dashboard<\/strong>, as usual. Otherwise, <strong>if the logged-in user is a customer or a shop manager, they will be redirected to the Shop page, i.e. to the <em>your-website-url\/shop<\/em> page.<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Please note, <em>customers<\/em> and <em>shop managers<\/em> are two user roles created by the WooCommerce plugin. As such, if you don\u2019t have WooCommerce installed on your website, this part of the code won\u2019t be executed. However, if you have the plugin, make sure that a Shop page exists on your website. Also, please note that you should adjust the code to reflect your page\u2019s slug if it\u2019s something other than <em>shop<\/em>. Finally, <strong>all users that don\u2019t fall under the previous two conditions (those whose user role isn\u2019t admin, editor, author, customer, or shop manager), will be redirected to the homepage.<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">if ( in_array( 'administrator', $user-&gt;roles ) || in_array( 'editor', $user-&gt;roles ) || in_array( 'author', $user-&gt;roles ) ) {\r\n\/\/ Admins, editors and authors are redirected to the WordPress dashboard\r\n$redirect_to = admin_url();\r\n} else if ( in_array( 'customer', $user-&gt;roles ) || in_array( 'shop_manager', $user-&gt;roles ) ) {\r\n\/\/ Customers and shop managers are redirected to the Shop page\r\n$redirect_to = home_url( '\/shop' );\r\n} else {\r\n\/\/ Everybody else is redirected to the homepage\r\n$redirect_to = home_url();\r\n}<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]As you can see, this is a rather straightforward piece of code. Having understood what it does, <strong>you can further improve or edit the example we offered to your liking.<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<strong>After you are done adjusting the code to your needs, you can insert it either in the functions.php file of your theme or inside a <a href=\"https:\/\/qodeinteractive.com\/magazine\/wordpress-site-specific-plugin\/\">site-specific plugin<\/a>.<\/strong> We will show you how to do the former, as it\u2019s quicker and simpler.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]However, before proceeding, we advise <a href=\"https:\/\/qodeinteractive.com\/magazine\/how-to-backup-wordpress-files\/\">making a backup of your website<\/a>, just in case. Also, if you need to, you should brush up on your knowledge on <a href=\"https:\/\/qodeinteractive.com\/magazine\/how-to-use-ftp\/\">the use of FTP<\/a> beforehand.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Then,<strong> log in to your server<\/strong> using your FTP credentials and <strong>navigate to your website\u2019s root WordPress directory<\/strong>, often called public_html.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"518\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/12\/Public-HTML-FTP.jpg\" class=\"attachment-full size-full\" alt=\"Public HTML FTP\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/12\/Public-HTML-FTP.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/12\/Public-HTML-FTP-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/12\/Public-HTML-FTP-768x411.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/12\/Public-HTML-FTP-620x331.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]Afterward, <strong>navigate to \/wp-content\/themes<\/strong> and <strong>click on your current theme\u2019s folder<\/strong> to open it. Then, <strong>locate the functions.php<\/strong> <strong>file<\/strong> within that folder, <strong>right-click on it<\/strong>, and <strong>select the <em>View\/Edit<\/em> option<\/strong>.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"600\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/FTP.jpg\" class=\"attachment-full size-full\" alt=\"FTP\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/FTP.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/FTP-300x186.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/FTP-768x476.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/FTP-620x384.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]<strong>Open the file<\/strong> using your preferred text editor and <strong>insert the code<\/strong> we included above at the end of your functions.php file.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"518\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/FTP-Code.jpg\" class=\"attachment-full size-full\" alt=\"FTP Code\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/FTP-Code.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/FTP-Code-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/FTP-Code-768x411.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/FTP-Code-620x331.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]Afterward, <strong>save the changes<\/strong> you made and <strong>upload the file back to your server<\/strong>, to override the old one that\u2019s there. Finally, <strong>you should test to see if all the redirections are working properly<\/strong> for all user roles you listed in the code.[\/vc_column_text][vc_empty_space height=&#8221;80px&#8221;][vc_widget_sidebar sidebar_id=&#8221;qi-banner&#8221;][vc_empty_space height=&#8221;81px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\">Final Thoughts<\/h2>\n<p>[\/vc_column_text][vc_column_text]Using WordPress redirect after login has many advantages, including improving the user experience of your customers and subscribers, managing a large number of users, or protecting your admin dashboard and the content found within against unauthorized edits. And, as you have seen from this article, you can implement it quite easily using appropriate plugins or custom code. No matter which of the methods you choose, we are confident that you will be able to redirect your users to the appropriate pages after login, and in record time. As such, we recommend you bookmark this article for any future instances where you might need to implement redirection of users after login.<br \/>\n[\/vc_column_text][\/vc_column][\/vc_row]<\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>There&#8217;s a lot you can do with a WordPress website, and that includes activating redirect after login for your users. Try it out today!<\/p>\n","protected":false},"author":11229,"featured_media":18945,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[4,13],"class_list":["post-18811","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-tips","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts\/18811","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/users\/11229"}],"replies":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/comments?post=18811"}],"version-history":[{"count":0,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts\/18811\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/media\/18945"}],"wp:attachment":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/media?parent=18811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/categories?post=18811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/tags?post=18811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}