Execute shortcode in custom field

<?php echo apply_filters('the_content', get_post_meta($post->ID, 'your_custom_field_here', true)); ?>

39 Comments

You must be logged in to post a comment.


  1. Have never used them. Look for a filter. If you figure it out feel free to post the solution here!


  2. Hi,

    I am trying to put a [shortcode] inside a repeater field, but I cannot make it work. The code you gave here it works fine for a normal field, but how do I use it to display a repeater field?

    thanks!


  3. This code works great !

    Thank you very much !


  4. I needed something like this for a template theme im working on with cart66 plugin! Thank you!


  5. Thanks for the info! Just what I needed for a theme we're working on.


  6. Thank you for your responce ! Unfortonatly i am not a code expert and i cant make a plugin from the scratch.

    the onlyway is to call somehow this code to show in the widget .

    if you like i can sendyou the code just to take a look

    Thanks again


  7. I would try a filter for the_excerpt instead, more than likely a recent posts widget will call up the excerpt instead of the content.

    Otherwise I would just do a recent posts widget from scratch, and use do_shortcode()


  8. Hi, this is a great tip and it solved my problem !

    in the post page it seems to work ok but when i try to call the shortcode in a widjet with recent posts i cant get it work

    my case is a countdown timer which is generated in each product by custom fields (which you gave me the solution)

    if is another way to call the snippet and try it would be great !

    Thanks


  9. Good deal. I think this snippet has been the most "life saving", based on the comments at least.

    If you do a lot of shortcode you must try this trick I came up with http://code.hyperspatial.com/1105/function-as-shortcode/

    This allows you to print php normally in the callback functions instead of "returning" the HTML


  10. You Saved my life!!!! Or at least my sanity ;P I've been scouring the internet for exactly this little tidbit. Thanks so much!


  11. You Saved my life!!!! Or at least my sanity ;P I've been scouring the internet for exactly this little tidbit, and with a deadline getting dreadfully close. Thanks so much!


  12. Never mind. It looks like it renders the output where ever you place the code. Not as part of the_content. Thanks.


  13. Could you supply a variation for those not wishing to print results as part of "the_content"?

    J


  14. Solid! Thanks for the fix, never needed to do this until now. And thanks for being so findable on Google, too 😀


  15. Put the snippet it a template file before the loop, say in single.php, if you are adding it to a functions file or an included php file that may be the issue.


  16. This code works great, however when I insert it into my custom post template, it ends up generating two "ends" of the document, and other plugins which add content to the end of the post (social buttons, post signature plugin) get duplicated.

    How do I solve this?


  17. Thank you so much for that tip!


  18. Another happy customer, thanks buddy!


  19. Thankyou so much, this helped immensly!


  20. Hi, will above approach work for genesis framework? I have tried but it really greats a mess. Thanks

    • I have no experience with that framework but this code is all php/wordpress core - so it should work on any wordpress install unless the theme or a plugin interferes.


  21. amazing...short and simple ! thanks


  22. That is the purpose of this exercise, look through the thread above. The snippet goes in your template file, like single.php - you need to change the name of the 'your_custom_field_here' to the name of the custom field you want to display that is connected to the post.


  23. hello,
    if i want to insert custom field value into the_content() how i do that please??


  24. Thanks this worked like a charm! :)


  25. [...] fonte: code.hyperspatial.com [...]


  26. This was a life saver...you rock!


  27. Thanks! Just what I needed!


  28. Not quite sure what you are getting at, but the shortcode you put in the custom field should run the same as if you were to put that shortcode into the post body.


  29. Hi nice trick

    But i use wp estore plugin for ebook store and i have to put shortcode with product id in post and it shows the paypal button for that product, is it possible that i just add id in custom field and it shows that button.

    Means a custom field which add a shortcode itself and will put product id as value.


  30. Typically this code would go into one of the wordpress template files that displays the blog posts. Like single.php or archive.php


  31. Where do I put this code?


  32. perfect ! you help in a problema that did take me more than a day ! Thankyou


  33. Every time I write some interesting php for a custom field I put it in the collective.
    They all get filed under the tag custom fields for quick access.
    Don't forget, you folks can store your own snippets on this site, just register and start storing them here.


  34. Wow,

    You helped me solve a problem now that has been going on for weeks! What a relief! Thank-you so much! I was almost going to give up.

    Thanks again!


  35. Great!!!!!!!!!!!!!!!!!!!!!!!!!!!!


  36. Thanks a lot buddy.really helpful :)


  37. Thanks for the tip, this helped me out big time!