Content Marketing

WordPress: How To Check If The User is Logged, Determine Their Role, And Modify Content

We have a lot of authors on Martech Zone but not all of them are familiar with WordPress and how to log in and publish on the site. WordPress can identify whether or not you’re logged into the platform using a user_level function that returns whether or not you’re logged in as well as what your role is.

Check User Role for Logged In WordPress User

WordPress has several default roles and capabilities:

  • Super Admin – somebody with access to the site network administration features and all other features.
  • Administrator – somebody who has access to all the administration features within a single site.
  • Editor – somebody who can publish and manage posts including the posts of other users.
  • Author  – somebody who can publish and manage their own posts.
  • Contributor – somebody who can write and manage their own posts but cannot publish them.
  • Subscriber – somebody who can only manage their profile.

You can dynamically change the displayed link on your site using this snippet using WordPress’

API… displaying the admin link for an author, but displaying an advertise link for anyone that isn’t logged in:

$user = wp_get_current_user();

if ( in_array( 'author', (array) $user->roles ) ) {
    wp_register('<li class="menuitem">','</li>');
} else {
    echo "<li class='menuitem'><a href='https://martech.zone/advertise/' title='Advertise'>Advertise</a></li>";
}

?>

Douglas Karr

Douglas Karr is CMO of OpenINSIGHTS and the founder of the Martech Zone. Douglas has helped dozens of successful MarTech startups, has assisted in the due diligence of over $5 bil in Martech acquisitions and investments, and continues to assist companies in implementing and automating their sales and marketing strategies. Douglas is an internationally recognized digital transformation and MarTech expert and speaker. Douglas is also a published author of a Dummie's guide and a business leadership book.

Related Articles

Back to top button
Close

Adblock Detected

Martech Zone is able to provide you this content at no cost because we monetize our site through ad revenue, affiliate links, and sponsorships. We would appreciate if you would remove your ad blocker as you view our site.