WordPress.org

Support

Support » Themes and Templates » Using Shortcode in Custom Fields

Using Shortcode in Custom Fields

  • I have an audio/video player that uses shortcodes to display the player. In the theme I am using the code for audio/video players is suppose to be entered in a custom field. I need to be able to have shortcodes parsed in this specific custom field in my theme. This is the isolated portion of the code in my single.php that calls on the custom field that I am dealing with:

    <div class="entry">
    <?php $video_code = thman_getcustomfield('video_code',get_the_ID()); if(!empty($video_code)) : ?><div class="video_code"><?php echo $video_code; ?></div><?php endif; ?>

    I need this section to check if the video_code field contains shortcode and if so parse the shortcode so that it will be processed and appear in the post as it would if the shortcode was inserted in the editor. If not then just process as normal.

    I have tried several different fixes from various forums to get this to work. I am in great need of some expert advice in modifying custom fields and shortcodes in themes.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You need to use the do_shortcode() call!

    UNTESTED:
    <?php echo do_shortcode('['.$video_code.']'); ?>

    HTH

    David

    Thanks. I will give that a try.

    I tried inserting your code in various ways into the code above and it didn’t work. What it did was just echo the shortcode again so that it appeared twice in the post which is typically the result I have been getting with all the potential solutions I have found from scouring the web.

    Thanks for the suggestion though. I know there is a solution to this puzzle somewhere.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Using Shortcode in Custom Fields’ is closed to new replies.