• Resolved bench22

    (@bench22)


    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)
  • 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

    (@bench22)

    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.