This <?php if ( current_user_can('contributor') ) : ?>
only checks the users capabilities and is used like this <?php if ( current_user_can('edit_post') ) : ?>
You could write a function like this in functions.php
:
function user_role_check( $role, $user_id = null ) {
$user = wp_get_current_user();
if ( empty( $user ) )
return false;
return in_array( $role, (array) $user->roles );
}
In your theme you would use it like this:
<?php if ( user_role_check( 'administrator' )): ?>
Do this
<?php else: ?>
Do this
<?php endif; ?>
Learn more about Roles and Capabilities: http://codex.wordpress.org/Roles_and_Capabilities
Related Posts:
- Allow BBPress participant role to trash topics
- Access methods in plugin template
- How to use nonce with front end submission form?
- Mega Menu Walker
- How to add a class to the attachment images
- How to export/import theme customizer settings?
- Why would a GET variable one one page of a site cause a 404 error when a GET variable works on another page of a site?
- How to loop through JSON data in wordpress WP REST API
- Why can I not use setup_postdata($post) in the sidebar?
- Drop down+sort blog posts date added/most popular
- How to remove “out of stock” variation options from size dropdown in woocommerce?
- WordPress Customizer: How can you have multiple active callbacks on one control?
- Activate different theme for temporary preview
- add_rewrite_rule with bottom priority doesn’t handle the WordPress pages
- wordpress custom endpoint multiple params
- Enable errors PHP WordPress 5.2
- Get WooCommerce shipping methods programmatically
- How do I output a database option that is an array into a get_posts array?
- Passing jQuery value using Ajax to a page template
- Change logo based on incoming domain
- Show Custom Taxonomy Title
- Why can’t I use “%s” format value in the WordPress function checked?
- WordPress widget/sidebar dividers?
- Add custom php database code above
- Help with some php math in WordPress
- max_input_vars: how many am I using?
- Multiple WordPress Menus that will only display all pages
- How to make drop down post title
- how to delete 30 day old data using PHP [closed]
- Remove meta description on certain pages
- WordPress not reflecting changed of the database
- Image media upload metabox
- Is there CSS to expand the gallery limit on Index Pages?
- Woocommerce related product text
- esc_html_e() is not translating string in wordpress [closed]
- WordPress, AJAX and pre_get_posts using conditional tags
- Limit 1 global comment per minute
- Font Awesome changing default WordPress Font
- Help with a $wpdb MySQL Query
- a:0:{} is replaced into database as s:6:”a:0:{}”;
- Echo a function inside a function
- Download full html page with CSV export plugin
- Advanced Custom Fields – display label and value only if value entered
- Use WordPress function in php file
- Is it bad to add html to a widget by closing and reopening the php tags?
- how to disabled a button when press three times
- $wpdb returns duplicate posts
- How Can I Edit the Registration Code?
- Is it possible to change content in my PHP file from WordPress dashboard
- My jQuery Ajax form submit is still refreshing page?
- load more button in plugin
- Illegal string offset error in wordpress theme options textarea
- Controlling image output size ACF repeater [closed]
- display specific widget to a page
- Get options from database using php class
- Output product category link from WP_Query
- Adding onload to body for certain pages
- Additional file upload in Gutenberg page options/featured image
- Delete images from media library when user deletes an image from ACF Gallery
- Change wordpress’ database data using ajax – how to get current user id?
- Add css class to string
- Replace custom SVG icons in Twenty Twenty-One
- Integrate otp in my custom singup form
- How to block specific user id in custom login form?
- Dropdown Category form. Only show Sub-Categories
- Display all categories including sub categories under a list ul
- WP Hook Before a post is created
- Unable to retrieve get_author_posts_url
- Store user form submitted information in post type
- Block that renders html saved in a php file
- Polylang and template files
- $_GET[‘title’] in WordPress
- Can’t update or install plugins in WordPress, php unidentified index
- Offset with ajax load more posts duplicates
- Add custom ID attribute to all woocommerce products on archive pages
- problem in using wpdb->prepare and a string placeholder
- Efficient way of querying for a “fallback” post?
- Shortcode in a $output statement
- WP Redirect with user nickname/username
- If else statement based on referral URL
- Archive page if else not working for post_excerpt and post_content
- add bootstrap modal after login in wordpress
- Hide sharing box and author box with a metabox on WordPress
- featured post as div background
- WordPress Website Featured Image Replacement Issue
- syntax error unexpected ‘}’ at 364 line
- get_post_meta no longer working
- Highlight posts currently being edited on multiple editor site?
- WordPress Plugin Receive a Link
- 500 error when using wp_upload_dir() [closed]
- How to use plugins_url() inside PHP stylesheet file [duplicate]
- Php echo into tag
- Using Excel formula in PHP. Use ^ symbol [closed]
- PHP warning Invalid argument supplied for foreach() on custom page template
- Assign new post author IF another user in custom field on post transition
- Create and publish a new post every Monday, listing the post titles and links to the posts published during the previous week
- Edit Error Page style
- How to sort wordpress posts by selecting a year from a drop down?
- PHP $_SESSION array – only showing current index
- How can I use AJAX in child theme template?