WordPress Quick Fix: Redirect certain user role to homepage on login - Code Pixelz
  • Web Design
  • WordPress
  • Miscellaneous
    • HTML5
    • CSS
    • Mobile
    • Inspirations
    • Freelancer
  • WordPress 101
  • Get in touch
    • Advertise with us
    • Contribute
    • Contact Us
Skip to Content
Code Pixelz
  • Web Design
  • WordPress
  • Miscellaneous
    • HTML5
    • CSS
    • Mobile
    • Inspirations
    • Freelancer
  • WordPress 101
  • Get in touch
    • Advertise with us
    • Contribute
    • Contact Us
Security Web Development WordPress

WordPress Quick Fix: Redirect certain user role to homepage on login

  • 2013-07-19
  • By Utsav Singh Rathour
  • 0 Comments

Today I will show you how you can redirect certain user role to homepage, or restrict certain user level from accessing the admin dashboard area in WordPress. Say you create a site where you have different user levels that can access certain part of your site (front end) using their login credentials. However you do not want them to get inside the Dashboard (even though the access is restricted). For that all you have to do is add the following snippet to your theme file’s functions.php

function wp_cp_redirect(){
if( is_admin() && !defined('DOING_AJAX') && ( current_user_can('subscriber') || current_user_can('contributor') ) ){
wp_redirect(home_url());
exit;
}
}
add_action('init','wp_cp_redirect');

What this does is redirects any user whose role is either ‘subscriber’ or ‘contributor’ back to the homepage every time they try to access the admin dashboard.

Also a bonus tip (I am feeling happy today ;) )

If you do not want to show the Admin Menu on top of the page once you login, you could use the following code to do so. Just paste it  into your theme’s function.php

 
add_filter( 'show_admin_bar', '__return_false' );

Show Love

  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Twitter (Opens in new window)

Related

redirect subscriber to home redirect to homepage after login restrict wp-admin user level user role wordpress redirect

Article By Utsav Singh Rathour

Utsav Singh Rathour is a WordPress Enthusiast and a blogger with over 10 years of experience and believes in building applications that not only tackles the problem but gives users a better interface. He is founder of Code Pixelz Media and blogs mainly at this place. Follow him at @rathour

Author Archives Author Website

Post navigation

Next Post Get counts of share, likes of...
Previous Post Working with WordPress

Related Posts

security-of-wordpress-site
WordPress

How to secure a WordPress website

  • 2017-01-04
  • 0 Comments
wordpress-site-audit
Security

HOW TO PERFORM A WORDPRESS SITE AUDIT

  • 2017-01-02
  • 0 Comments
Web Development

3 Insanely Popular WP Plugins that are Making Your Website Vulnerable

  • 2014-07-09
  • 2 Comments
Security

How secure is your website?

  • 2011-05-06
  • 0 Comments

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 

Need Job Listing Theme?

Robolist-Job-Listing-Theme-Code-Themes

 

Need Hosting?

Web Hosting

  • Latest Posts
  • Most Popular

The most essential WordPress Directory...

  • 2022-03-21
0

Things to consider when hiring a remote...

  • 2021-12-20
0

Must-Have WordPress Plugins for...

  • 2021-12-08
0

30+ Top Best Premium & Free...

  • 2021-11-24
0

Holiday WordPress Deals for 2021

  • 2021-11-17
0
WordPress Ajax Form-CodePixelz

Tutorial : How to create a Ajax Form in...

  • 2019-08-05
5

Extending WordPress. Making use of...

  • 2012-06-17
2
How-to-create-custom-post-type-Code-Pixelz

How to create a Custom Post Type...

  • 2019-07-22
0

How to: Add new column on user listing...

  • 2014-01-29
0

Need help with WordPress?



Popular Posts

  • Tutorial : How to create a Ajax Form in WordPress
  • 20+ Best Free Lawyer WordPress Themes for Law Firms and Attorneys (Updated)
  • Top 7+ Free Hotel Booking WordPress Plugins for Accomodations (Updated)
  • Extending WordPress. Making use of Custom Post Types
  • How to create a Custom Post Type without using a plugin in WordPress

Follow us on Twitter

My Tweets

Pages

  • About Code Pixelz
  • Advertise with us
  • Contribute
  • Get in touch
  • Privacy Policy
Powered by Magazine theme from Code Themes Co
Back To Top
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT