Advanced Custom Fields
How to add SHORTCODE to a PHP Custom Field (2 posts)

  1. yourdaddy
    Posted 4 years ago #

    I have a PHP file which i added Custom Fields PHP options, and i want to add shortcodes to the end result which is a [member] info…[/member] which basically requires to be logged in to display. How can i get this to show up?
    [member]<?php the_field(‘price’); ?>[/member]
    Doesnt work…


  2. yourdaddy
    Posted 4 years ago #

    Ok to all the useless help i got, from thousands of people that must have clicked on this and decided to not even bother, I have found the solution and will share it to be remembered as someone who actually helps and supports DIY aswell as WordPress Fanatics!

    <?php $var = get_post_meta($post->ID, 'CUSTOM FIELD NAME', true); if ($var == '') { } else { echo do_shortcode( '[open your short code]' . $var . '[/close your short code]'); } ?>
    Now like i said, i was trying to apply a shortcode through a php file, using <?php echo do_shortcode("[Shortcode]"); ?>
    Didn't seem to work, as it didnt allow me to do add my <?php the_field('model_#'); ?> between opening and closing shortcodes, it would break. Obviously i was doing it wrong!

    After hundreds of Re-Worded Google Search Queries I found it and
    Used it as a guide to my solution/example code. But seem to have asked a similar/same question just worded differently.


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Advanced Custom Fields
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.