3

I am trying to incorporate an image slider shortcode into a custom WordPress theme template, so that the client will be able to paste the shortcode into the custom field and the template will read this and display it correctly. I do not want the client to paste the shortcode in the body of the post, as the slider needs to be displayed outside of the post wrapper (at full browser width).

I don't know much about php, so would really appreciate any help with this!

The code I have so far to display the slider via the template is:

<?php echo do_shortcode("[metaslider id=27]"); ?>

And to display the output of custom fields I have:

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

Each of these works on its own, but I need to combine them, so that the client doesn't have to edit the template just to add the shortcode. So I am thinking something like this should work:

<?php echo do_shortcode("[<?php echo get_post_meta($post->ID, 'slider', true); ?>]"); ?>

... but it doesn't.

Many thanks in advance for any help with this.

C

5
  • You cant use do_shortcode like that. You can only use do_shortcode to reference an actual shortcode. Commented Aug 5, 2013 at 20:04
  • So what do you suggest in this instance? How do I get this to work? Commented Aug 5, 2013 at 20:06
  • I'm still staring at this and wondering myself. It's a good question :) Commented Aug 5, 2013 at 20:08
  • I think I just figured it out. This seems to work: Commented Aug 5, 2013 at 20:09
  • 1
    <?php echo do_shortcode(get_post_meta($post->ID, 'slider', true)); ?> Commented Aug 5, 2013 at 20:10

1 Answer 1

2

Simply pass the return value of get_post_meta (which would contain the shortcode as far as I understood) to the do_shortcode function as an argument:

do_shortcode(get_post_meta($post->ID, 'slider', true));
Sign up to request clarification or add additional context in comments.

1 Comment

Figured it out then this answer came through confirming. Thanks folks - my first time posting here - great experience.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.