Title: do_shortcode in widget area inside functions.php
Last modified: November 14, 2019

---

# do_shortcode in widget area inside functions.php

 *  Resolved [bench22](https://wordpress.org/support/users/bench22/)
 * (@bench22)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/do_shortcode-in-widget-area-inside-functions-php/)
 * Hi there,
    I need to insert a shortcode (only for single page posts) inside the
   sidebar, depending on post_id … like this: do_shortcode(‘[example-name id=XXX]’);
   is there a way…? I’m trying to use the functions.php file of my child theme but
   doesn’t seems to work… thanks!

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

 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/do_shortcode-in-widget-area-inside-functions-php/#post-12128547)
 * If you want to use different post IDs, you should put the code into the child
   theme’s copy of the sidebar file. There would be an if statement to check for
   the correct post and then a direct call to the shortcode handler function (so
   it doesn’t have to parse the shortcode).
 * If it’s always the same post ID, but you want it to appear only on certain posts,
   use a plugin like Dynamic Widgets which allows you to control when the widget
   appears, and put the shortcode into a text widget.
 *  Thread Starter [bench22](https://wordpress.org/support/users/bench22/)
 * (@bench22)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/do_shortcode-in-widget-area-inside-functions-php/#post-12131742)
 * Hi Joy,
    thank you for replying, it worked like a charm! 😉

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

The topic ‘do_shortcode in widget area inside functions.php’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [bench22](https://wordpress.org/support/users/bench22/)
 * Last activity: [6 years, 6 months ago](https://wordpress.org/support/topic/do_shortcode-in-widget-area-inside-functions-php/#post-12131742)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
