Your problem is that current_user_can() takes a capability not a user role. So, to check for an administrator, for example, you might use:
if ( current_user_can( 'manage_options' ) ) { ... }
because ordinarily only admins can manage options.
You’d have to tie your custom user roles to capabilities that correspond to their roles, which are defined for each role when you create it with add_role(). For a complete listing of built-in WP roles and their corresponding capabilities, see the codex.
Related Posts:
- how to create a conditional content_width for a wordpress theme?
- How to hide and content from auto-generated excerpts?
- How to tell if the user is an admin?
- Why is unfiltered html allowed in custom fields for author / contributor roles?
- Different Admin Theme – Based on Role?
- current_user_can Not Always Working Properly
- How can I detect hierarchal relationships beyond children (grandchild, great-grandchild, etc)?
- Add, edit specific CPT with custom role
- Limit number of users a role can create
- Question regarding WP multisite feature
- How to change footer or for different kinds of users in wordpress?
- Where do you add code in custom fuctions so it works on a specific page?
- Why is the `if else` not working?
- Show only pages you are author of
- hide/show a div in wordpress
- Conditional loop based on current page
- Checking conditionals
- Explanation of User Roles and Capabilities
- When to use add_action(‘init’) vs add_action(‘wp_enqueue_scripts’)
- Change admin bar to default:off
- How to add Color Picker in Theme Options for the following?
- Template for individual post designs
- Theme Review: post thumbnail, header image, content width
- How to determine if a category is empty?
- The seventh parameter passed to add_submenu_page()
- What would happen if the admin installs a plugin when the plugin is included in the theme?
- How do I get my child-theme to work with my theme’s includes folder?
- wp_insert_post breaks rewrite rules
- Where can I find a good reviewed collection of Twenty Ten child themes?
- how to create theme based widget that can be drop in sider bar or footer
- CSS in child theme not overriding the parent theme [closed]
- Template Hierarchy for get_header()
- Remove frameborder attribute from iframes
- how do I get a sidebar’s id or number for use with is_active_sidebar()
- Looking for the code in twentyten that allows users to select images for the header/banner
- List categories and exclude child categories
- WordPress as a data intensive web app
- How to determine which custom header image is being shown
- using wordpress without javascript
- Theme Check: Could not find post_class
- Override theme programmatically
- Set a static front-page as a landing page programmatically
- Custom URL parameters in template files
- How do I remove TinyMCE text format
- can’t understand _e function well
- WP 3.1 upgrade breaks AutoFocus+ theme
- Comment entry screen shows even though “Allow Comments” is unchecked
- Custom WordPress Theme – Search not working on posts
- Change content layout based on menu hierarchy
- Theme Loading Into Dashboard
- How to make theme elements customizable in wordpress?
- Where to hook settings api init
- attachment.php code or tutorial
- How to filter or remove the “title” attribute from category links
- Change “Thumbnail”, “Medium” and “Large” image sizes using functions.php?
- How to obtain a reference to the_excerpt() from custom loop
- defining a folder location in order to recall it
- Remove CPT slug from URL WordPress
- JavaScript stops working on selectively refreshed sections one inside the other
- Why doesn’t my css work when I check my theme on mobile devices? [closed]
- Changing Header Image Every N Minutes/Seconds
- Can I add an icon & function to the “Upload/Insert” toolbar at the top of the content editor?
- underscores use of the article element on the page template
- Ideal inline dynamic CSS injection
- How to create and populate with few links a menu in child theme functions.php?
- Plugin does not work in custom theme
- How to Manually Code Shortcode?
- Making custom woo themes
- Where does the uploaded image go?
- Previous and Next links not populating, have I missed something?
- Single.php the_excerpt loads same as the_content not loading read more line
- Where to put custom page templates in theme?
- Pagination not working on custom post page
- How to conditionally add a wp_filter
- How to set default values for edit_post_link() in my theme?
- Creating an advanced searchform based on select boxes
- I don’t think WordPress is loading jquery or bootstrap js
- PHP Parse error: syntax error, unexpected ‘endwhile’ (T_ENDWHILE), expecting elseif (T_ELSEIF) or else (T_ELSE) or endif (T_ENDIF) on line 124
- how use ajax to custom page template
- hide theme files for admin beneath root
- Is it possible to show sort page excerpt in search.php
- How to display home page last modified date in anywhere of wordpress theme?
- Loop is breaking my theme. How can I fix?
- How do you remove the “Your Main Benefit Statement Goes Here.” From one of my pages?
- Error Handling when building WordPress themes
- Show all menu levels except top level. How to exclude top level of a menu?
- Recall translations made with Poedit
- Standard technique for AJAX post endpoint: WP REST or WP API?
- How to achieve this navigation style in wordpress navigation
- How to dowload and edit content of a website
- After theme change the menus have to be manually linked to the corresponding theme location
- How Does One Create a Global Variable Repository
- Passing a location-dependent array via wp_localize_script within a shortcode
- Retrive posts thumbnail in original size
- Global Navigation menu in diiferrent wordpress setups
- How can i display a 4 diferent themplate for the archive page
- After a while attachment meta data is missing “sizes” data
- Align images to the left of the content
- Add text when displying attribute with a hook on single product page
- WooCommerce custom add to cart buttons does not add products to cart if you’re logged out