Sometimes it could be useful to allow shortcodes in the description fields of your add-ons. As an example, you might want to give the users the option of clicking a link to display further information.
To enable shortcodes in add-on descriptions, use the following snippet:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Allow shortcodes in field description | |
*/ | |
function prefix_shortcode_in_description( $description, $item, $additional_info='' ) { | |
$field_description = ! empty( $item['field_description'] ) ? $item['field_description'] : ''; | |
$description = sprintf( | |
'<p class="pewc-description">%s%s</p>', | |
do_shortcode( $field_description ), | |
$additional_info | |
); | |
return $description; | |
} | |
add_filter( 'pewc_filter_field_description', 'prefix_shortcode_in_description', 10, 3 ); |
This is how to add a snippet.
Adding a lightbox pop-up to the description field
As an example, here’s how to add a pop-up box to the field description:
- Install the Shortcodes Ultimate plugin
- Add the following shortcode to your field’s description
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[su_lightbox type="inline" src="#my-custom-popup"] Click here to open lightbox with HTML content [/su_lightbox] | |
[su_lightbox_content id="my-custom-popup"] | |
<h3>Custom HTML content</h3> | |
Any <strong>HTML</strong> <em>tags</em> can be used here. Other shortcodes are also [su_highlight]allowed[/su_highlight]. | |
[/su_lightbox_content] |