Restricting content using a shortcode

This scenario explains the creation of a shortcode using all the four shortcode components discussed in the previous section. Basically, we need a shortcode that accepts content and displays the output only to authorized users, while providing a custom output for unauthorized users. Let's consider the shortcode needed for this scenario:

[wpquick_restrict_content  role=subscriber]  Content to be protected [/wpquick_restrict_content]

The previous shortcode has one attribute for specifying the user roles not authorized to view the content and the content to be protected within the opening and closing tags. Now we have to match the previous shortcode with the code used in the Structure of a shortcode diagram. ...

Get WordPress Development Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.