Skip Navigation

[Resolved] Conditional display of a shortcode

This thread is resolved. Here is a description of the problem and solution.

Problem:
The customer asked how the post edit link can be shown only to users with a specific user role.

Solution:
Guided that if the website has the Toolset Access plugin active, you can wrap the edit link inside the 'toolset_access' shortcode.

And if the Access plugin is not active, the conditional display shortcode can be used.

Examples available in the reply:
https://toolset.com/forums/topic/conditional-display-of-a-shortcode/#post-2293719

Relevant Documentation:
n/a

This support ticket is created 2 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Author
Posts
#2293145

Hi

Inside my custom post type 'applications' there is an update status button displayed with shortcode that edits the post type.
(in the applications custom post type there are 2 people involved, one applicant and one job owner)

this is the shortcode:
[toolset-edit-post-link content_template_slug='Application-Status-Edit-Template' target='self']Update Status[/toolset-edit-post-link]

I want to display this shortcode conditionally so that only the role 'job owner' can see this button and the applicant can't.

Thank you!

#2293719

Hi,

Thank you for contacting us and I'd be happy to assist.

If your website has the Toolset Access plugin active, you can wrap the edit link inside the 'toolset_access' shortcode for this, to show it only to users with a specific role:


[toolset_access role="Role Name" operator="allow"]
[toolset-edit-post-link content_template_slug='Application-Status-Edit-Template' target='self']Update Status[/toolset-edit-post-link]
[/toolset_access]

Note: You'll replace 'Role Name' with the actual user role name that you'd like to allow.

In case, you're not using the Toolset Access plugin, you can instead, use the conditional display shortcode:


[wpv-conditional if="( '[wpv-current-user info="role"]' eq 'roleslug' )"]
[toolset-edit-post-link content_template_slug='Application-Status-Edit-Template' target='self']Update Status[/toolset-edit-post-link]
[/wpv-conditional]

Note: You'll replace 'roleslug' with the actual user role slug that you'd like to allow.
( To see the slug of any user role, you can log in as that user role and see the output of the shortcode [wpv-current-user info="role"] )

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2294299

My issue is resolved now. Thank you!