0

I need to be able to display different shortcodes inside custom fields.

I have found a method that almost works perfect, but since that uses get_content, it also shows the main featured image of the page.
After the image that's output, the correct content that the shortcode outputs is displayed correctly. How can I stop the image from being output in the first place?

I'm using css to hide it, but would rather not have it output at all. I've tried using this other method which used get_the_content instead, and that doesn't work.
The shortcode content doesn't even show at all with that method.

I also found this:

echo preg_replace("/\< *[img][^\>]*[.]*\>/i","",get_the_content(),1); 

Does anyone know how to make that filter work for me with the code I'm using (shown in the pastebin link).

1 Answer 1

0

No need to deal with the content, use the do_shortcode function directly on your metadata:

echo do_shortcode( $your_meta_data );
9
  • Hey, thanks for your reply, but that is how I normally use my short codes in my custom template pages, but this time I will need to be able to use different short codes on numerous pages, and will need to be able to do this in the pages backend. Not by editing my templates everytime. Dec 31, 2012 at 2:20
  • How does it differ from the method you posted? You're just running your meta data through this function rather than applying content filters. You don't have to hardcode the shortcode into the template.
    – Milo
    Dec 31, 2012 at 2:29
  • In other words, when I use the method that you posted, the only thing that is output is the actual words, [my custom shortcode text shows] in my page, and not the content that the short code should be outputting. Dec 31, 2012 at 2:43
  • That shouldn't be the case, does this happen with all shortcodes?
    – Milo
    Dec 31, 2012 at 2:56
  • No, short codes work fine on their own, but when trying to insert a short code inside a custom field, I have to use the method I posted on Pastebin. It works, but I just need it to not output the featured image along with it. Dec 31, 2012 at 3:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.