I have a custom field in a custom post type. The custom field is a tinymce editor and I should echo out what user enters on it. If user enters text it is shown as well but when an image or a gallery is inserted the output is:

[gallery ids="221,207"]

here is my code:

$content  = get_post_meta( get_the_ID(), 'company-catalog', true);
    if(isset($content) && !empty($content)){?>
        <h2>Catalog</h2>
        <div class="company-tech"><?php echo $content;  ?></div>
    <?php } ?>

how can I force wp to show image gallery or single image instead of image code?

  • I could show gallery with do_shortcode() but I am not sure is right way to do that. – ehsan Sep 13 at 8:05
$content  = get_post_meta( get_the_ID(), 'company-catalog', true);
    if(isset($content) && !empty($content)){?>
        <h2>Catalog</h2>
        <div class="company-tech"><img src="<?php echo $content;  ?>" /></div>
    <?php } ?>

img src tag added.

  • As I told the output of $content is something like: [gallery ids="221,207"] . It can not be used like this. – ehsan Sep 13 at 8:39
  • sorry. i have not used tinymce. – David Corp Sep 13 at 8:44

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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