Title: Shortcodes in PHP code widget?
Last modified: August 20, 2016

---

# Shortcodes in PHP code widget?

 *  Resolved [johnsalomon](https://wordpress.org/support/users/johnsalomon/)
 * (@johnsalomon)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/shortcodes-in-php-code-widget/)
 * Hi,
 * I am trying to create a shortcode inside a php code widget by calling a custom
   field, like so:
 * 1. I have a shortcode in my post, with format [flickrgallery setid=”<number>”]—
   for example:
 * _[flickrgallery setid=”72157626892022672″]_
 * (This part works and places a Flickr thumbnail grid from that particular set 
   in my post).
 * 2. I have defined a custom field, _per\_post\_widget\_content_, in this particular
   post it has value _72157626892022672_ (same as above)
 * 3. I am trying to figure out how to use a php code widget to not just output 
   the same as in step #1, i.e. _[flickrgallery setid=”72157626892022672″]_ but 
   to actually process it and display my thumbnails in the widget. So far I have
   tried:
 * _<?php echo ‘[flickrgallery setid=”‘; echo get\_post\_meta($post->ID, ‘per\_post\
   _widget\_content’, true); echo ‘”]’; ?>_
 * However, the best I can get it to do is to output the shortcode inside the widget,
   but not actually do anything with it.
 * When I use a plain text widget, however, and just put in the full shortcode, 
   it works (but that won’t let me use the custom field on a per post basis…)
 * I don’t think eval would do it, since I don’t think shortcodes are actually php
   code, but at this point I’m lost.
 * Anyone? I stink at PHP…

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/shortcodes-in-php-code-widget/#post-2162267)
 * you could try to use `do_shortcode()` [http://codex.wordpress.org/Function_Reference/do_shortcode](http://codex.wordpress.org/Function_Reference/do_shortcode)
 * although some things with square brackets are not actual shortcode, but get rendered
   by a filter function on ‘the_content’ and with regular expressions.
 * what plugin is this `[flickrgallery setid="72157626892022672"]` coming from?
   
   check if this plugin actually has `add_shortcode('flickrgallery',` in its code.
   otherwise you might neet to look for the main function in the plugin. double 
   check the documentation of the plugin, if any.
 *  Thread Starter [johnsalomon](https://wordpress.org/support/users/johnsalomon/)
 * (@johnsalomon)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/shortcodes-in-php-code-widget/#post-2162268)
 * Hiya,
 * I will give that a shot. This is actually defined in a theme – Autofocus Pro+
   by Allan Cole. Documentation is non-existent, I’m afraid.
 * I’ve tried
 * _<?php do\_shortcode(echo ‘[flickrgallery setid=”‘; echo get\_post\_meta($post-
   >ID, ‘per\_post\_widget\_content’, true); echo ‘”]’;); ?>_
 * and it’s complaining about expecting ‘)’ (where?!?) – apologies for the boneheaded
   question, I assume I’d need the echo inside the parentheses?
 * Thanks very much for the advice.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/shortcodes-in-php-code-widget/#post-2162270)
 * there is also:
    [http://digwp.com/2010/03/shortcodes-in-widgets/](http://digwp.com/2010/03/shortcodes-in-widgets/)
 * add this to functions.php:
    `add_filter('widget_text', 'do_shortcode');`
 * (not sure if this will work with the php code widget)
 *  Thread Starter [johnsalomon](https://wordpress.org/support/users/johnsalomon/)
 * (@johnsalomon)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/shortcodes-in-php-code-widget/#post-2162282)
 * the add_filter didn’t work, but this is ok:
 * <?php echo do_shortcode(‘[flickrgallery setid=”72157626892022672″]’); ?>
 * That means do_shortcode is what I’m looking for, thanks!
 * However, I can’t explicitly specify the shortcode in the widget, as I’d have 
   to have a widget per post (each post has a Flickr gallery of its own).
 * Any chance you can give me a clue how I’d get all three parts of the shortcode
   into the do_shortcode parentheses?
 * Again, thank you kindly, this is already a huge help.
 * _[continued here: [http://wordpress.org/support/topic/complex-do\_shortcode-statements?replies=2#post-2199313](http://wordpress.org/support/topic/complex-do_shortcode-statements?replies=2#post-2199313)]_

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Shortcodes in PHP code widget?’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 4 replies
 * 2 participants
 * Last reply from: [johnsalomon](https://wordpress.org/support/users/johnsalomon/)
 * Last activity: [14 years, 11 months ago](https://wordpress.org/support/topic/shortcodes-in-php-code-widget/#post-2162282)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
