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
- Best practices for monitoring the need for future updates on a theme that I developed?
- My child theme doesn’t work Error: “The parent theme is missing. Please install your parent theme”
- do_shortcode() doesn’t do shortcodes ;)
- HowTo: Add Class to Sidebar Widget List-Items
- Theme file for all pages that are a child of a specific page
- Different wordpress 404 template for different post type [duplicate]
- Strategy to get post meta for use outside the loop
- Authentication / login mechanism (non wp-admin)
- WordPress Customizer Typography: How to load just the unique Google Fonts?
- Can we add more than one control under a setting in WP theme customizer?
- Widgets panel not displaying in the Theme Customizer
- How to show next Post Thumbnail image in WordPress using current post id
- How to add a section to the menus configuration, offering hard coded items?
- Am I using get_posts wrong?
- Get background color for Live Preview with Theme Customization API?
- Call to undefined function get_current_screen() on my localhost
- Cache Busting using htaccess Rewrite rule?
- How to add oEmbed support to my theme?
- WordPress Multisite: Have the same header and footer of main-blog on all sub-blogs
- Custom header images won’t appear when set to random
- Modify Javascript Configuration Options for Theme Customizer Colour Picker
- Difference between is_page and is_page_template
- How to Globally Use wp_localize_script() Ajax URL
- add filter not working when cancatenating variables
- How to Edit the style of header title of Twenty Eleven Theme?
- Override parent theme’s include file from child theme
- WordPress Theme Development: How to redirect templates the right way?
- Creating Theme Options Page
- How can I let templates choose which stylesheets are enqueued?
- WordPress with broken paging page 3
- Location of theme options page menu icon
- Is it possible to edit the styling of the admin panel from within a custom theme?
- Can’t login unless twentyfifteen theme is active
- the_excerpt(); tag not working
- How to implement a $_SESSION alternative in WordPress inside a theme without a plugin?
- Storing the contents from txt file into The_Contents”
- Differences between developing custom themes for wordpress.com and wordpress.org?
- Easy to develop on a URL that is changed for production?
- How to show custom meta_key in each li of menu
- Can I add multiple arrays within add_theme_support( ‘colors’ )?
- Customizer – loading settings/controls/sections/panels based on a id/page id
- Where to place template files?
- [&hellip appearing instead of […]
- Getting author URL outside the loop
- Replace single_template filter with what for default posts?
- Change image size depending on page
- Is there Photo Categories?
- How to include a mu-plugin as a theme dependency?
- Why still output /wp-content/themes/twentynineteen?
- How to use ajax in wordpress and sending the data without refreshing ?
- Adding an external link to product grid list pages for woocommerce
- add shortcode support in customizer
- How to make my themes compatible with different WordPress versions?
- License of the used Bootstrap Theme is not GPL compatible
- Customize Option Framework
- How to include posts with a theme
- Under theme folder, what’s sequence of action for index.php, page.php, single.php?
- Register a custom post type as public = false, but have content appear in search engines?
- Theme author.php transfer
- How to display only author’s name for the current post?
- How can I include custom Gutenberg Blocks in a theme?
- WordPress displaying two different headers, one at top and one below footer
- How to show metabox on page if it is using a template
- Mix it up & WordPress
- two col layout bootstrap 4 with one fixed col and fade in effect on image
- Styling the website via the customizer – do the changes stay after theme update?
- How to submit a guest post with rich text editor?
- Theme Development : License help
- show posts in different styling
- How to throw the “We need ftp info” at a user
- Infinite scroll loads new posts several times
- How to reduce repetitive code
- How to filter content by language with WPGlobus
- Enqueue script/style with multiple GET parameters
- Is it possible to create more than one design in a WordPress theme? [closed]
- Next Post Link not working with parameters to restrict to same term
- How to install Woocommerce without plugin?
- Correct way to make a title a link
- Is there a WordPress theme or plugin with built-in user management
- Dynamic nav menu with icons [closed]
- WordPress administration is gone after creating base theme
- Is there any filter or action hook to remove layout classes from appearing in my templates?