Discover in this tutorial how to limit the blocks available in the WordPress editor depending on the user role.
With time the block editor is offering more and more blocks. This is great as it gives you more versatility when creating content, but it can also give “too much to choose from” for some users.
There is an option to hide the blocks that you do not want to be shown in the editor by clicking on the three dots at the top right and selecting: Tools > Block Manager.
But this does not prevent the blocks from being loaded and being accessible from the manager for other users.
With the arrival of the block and site editor to WordPress, one of the concerns of designers and developers is that the end user has “too much” control over the design and can “disrupt” the work of the professional.
In a previous tutorial I explained how to unregister native blocks from the WordPress editor but if what you want is to have a more granular control, depending on the user role, I recommend you to follow the strategy that I’m going to explain below.
Limit the blocks displayed in the WordPress editor depending on the user role
Add the following code at the end of functions.php or in your functionality plugin:
To see this and another 1091 code snippets of this website, login or subscribe here.
In this code you use the allowed_block_types_all
filter with the current_user_can
function so that only certain blocks are displayed to users who are not allowed to publish pages, i.e. with author (or similar) role.
You can play with the capabilities of the user role to get the result you want. For example, if you want to limit the blocks to all users who are not administrators you can use the following code:
To see this and another 1091 code snippets of this website, login or subscribe here.
In both cases, the blocks you keep accessible are:
-
'core/heading'
: Header block -
'core/image'
: Image block -
'core/list'
: List block -
'core/paragraph'
: Paragraph block -
'core/columns'
: Columns block -
'core/buttons'
: Button block
But the idea is that you adjust it to what you are interested in.
Here you have the list with all the WordPress native blocks, categorized:
Text
- Paragraph
(core/paragraph
) - Header
(core/heading
) - List (
core/list
) - Quote (
core/quote
) - Code
(core/code
) - Preformatted
(core/preformatted
) - Pullquote (
core/pullquote
) - Table (
core/table
) - Verse (
core/verse
)
Layout
- Columns
(core/columns
) - Group
(core/group
) - More
(core/more
) - Page break (
core/nextpage
) - Separator (
core/separator
) - Spacer (
core/spacer
) - Buttons
(core/buttons
) - Text columns (deprecated)
Widgets
- Shortcode
(core/shortcode
) - Files
(core/archives
) - Calendar (
core/calendar
) - Categories
(core/categories
) - Custom HTML
(core/html
) - Latest comments
(core/latest-comments
) - Latest posts
(core/latest-posts
) - RSS
(core/rss
) - Search
(core/search
) - Social icons
(core/social-links
) - Tag cloud
(core/tag-cloud
)
Embedded
- Twitter
(core-embed/twitter
) - YouTube
(core-embed/youtube
) - Facebook
(core-embed/facebook
) - Instagram
(core-embed/instagram
) - WordPress
(core-embed/wordpress
) - SoundCloud
(core-embed/soundcloud
) - Spotify
(core-embed/spotify
) - Flickr
(core-embed/flickr
) - Vimeo
(core-embed/vimeo
) - Animoto
(core-embed/animoto
) - Cloudup
(core-embed/cloudup
) - Crowdsignal
(core-embed/crowdsignal
) - Dailymotion
(core-embed/dailymotion
) - Hulu
(core-embed/hulu
) - Imgur
(core-embed/imgur
) - Issuu
(core-embed/issuu
) - Kickstarter
(core-embed/kickstarter
) - Meetup.com
(core-embed/meetup-com
) - Mixcloud
(core-embed/mixcloud
) - Reddit
(core-embed/reddit
) - ReverbNation
(core-embed/reverbnation
) - Screencast
(core-embed/screencast
) - Scribd
(core-embed/scribd
) - Slideshare
(core-embed/slideshare
) - SmugMug
(core-embed/smugmug
) - Speaker Deck
(core-embed/speaker-deck
) - TED
(core-embed/ted
) - Tumblr
(core-embed/tumblr
) - Twitch
(core-embed/twitch
) - Videopress
(core-embed/videopress
) - WordPress.tv
(core-embed/wordpress-tv
)
Media
- Image
(core/image
) - Gallery
(core/gallery
) - Audio
(core/audio
) - Cover
(core/cover
) - File
(core/file
) - Media and text
(core/media-text
) - Video
(core/video
)
Theme
- Navigation
(core/navigation
) - Custom Link
(core/navigation-link
) - Home link
(core/home-link
) - Submenu
(core/navigation-submenu
) - Site Logo
(core/site-logo
) - Site Title (
core/site-title
) - Site Theme
(core/site-tagline
) - Query Loop
(core/query
) - Entry Template
(core/post-template
) - Entry Title
(core/post-title
) - Entry Excerpt
(core/post-excerpt
) - Entry Feature Image
(core/post-featured-image
) - Entry Content
(core/post-content
) - Entry Author
(core/post-author
) - Entry Author biography
(core/post-author-biography
) - Entry Author Name (
core/post-author-name
) - Entry Date
(core/post-date
) - Entry Modification Date
(core/post-modified-date
) - Entry Categories
(core/post-terms
withtaxonomy:category
) - Entry Tags
(core/post-terms
withtaxonomy:post_tag
) - Pagination
(core/query-pagination
) - Entry List
(core/posts-list
) - Avatar
(core/avatar
) - Entry Navigation Link
(core/post-navigation-link
) - Next Entry
(core/post-navigation-link
withdirection:next
) - Previous Entry
(core/post-navigation-link
withdirection:previous
) - Read More
(core/read-more
) - Comments
(core/comments
) - Comments Title
(core/comments-title
) - Comment Template
(core/comment-template
) - Comment Author Name (
core/comment-author-name
) - Comment Date
(core/comment-date
) - Comment Content
(core/comment-content
) - Comment
Reply-link (core/comment-reply-link
) - Comment Edit-Link
(core/comment-edit-link
) - Comment Pagination
(core/comment-pagination
) - Comment Entry Comment Form (
core/post-comments-form
) - Post Comment (deprecated)
(core/post-comment
) Login/Logout (core/loginout
)- Term Description
(core/term-description
) - Archive Title
(core/archive-title
) - Search Results Title (
core/search-results-title
) - Template Part
(core/template-part
)
You can see the updated list in the official documentation.
Conclusion
Now you know how to limit the blocks displayed in the block editor depending on the user role.
This allows you to give access to clients or collaborators so that they can modify the content but limiting it to where you want.
Any questions? I read you in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉