how to find if any valid shortcode is used in a field coming from custom database table in WordPress

Here’s my problem: I have created a custom plugin in which user can create a Lightbox and style and put some content in it.

In content user can enter any type of text, HTML or valid/registered WordPress shortcodes and when clicks save everything is stored to a custom database table. Everything works fine till here.

Read More

I can display all the content in lightbox div.
I use simple code for this:

<div id="lightbox-content"><?php echo $ary['lightbox_contents']; ?></div>

Where $ary is an array containing specific lightbox row data from database table.

But when WordPress shortcode/(s) (registered/valid) is used, the shorcode is displayed as it is and its not processing. Eg. it prints and not the content which should be printed for this shortcode.

I know a way to process a shortcode for which I know the name using do_shortcode method. But for lightbox content I won’t know which shortcode user is going to use and with parameters (if any).

How to print content for shortcode with above scenario given?
Any help or hint will be appreciated.

Related posts

Leave a Reply

1 comment

  1. You should be able to just call do_shortcode on the value. It’ll run any shortcodes if it finds some and won’t affect the rest of the content.

    echo do_shortcode( $ary['lightbox_contents'] );