WordPress.org

Ready to get started?Download WordPress

Forums

Using Shortcode in Custom Fields (4 posts)

  1. mckaymultimedia
    Member
    Posted 2 years ago #

    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.

  2. Digital Raindrops
    Member
    Posted 2 years ago #

    You need to use the do_shortcode() call!

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

    HTH

    David

  3. mckaymultimedia
    Member
    Posted 2 years ago #

    Thanks. I will give that a try.

  4. mckaymultimedia
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic