0

I think this will be pretty easy to answer...My php knowledge isn't great!

I have used the Advanced Custom Fields plugin to create an 'add Slideshare shortcode' custom field in my page. The user would add shortcode generated from Slideshare enabling them to display their slideshare presentation, see below...

[slideshare id=7901921&doc=embed-slideshare-110509200429-phpapp01]

My issue is that I cannot add the call for the custom field to the "echo do_shortcode" command in my page.php. I have..

<?php   $slides = the_sub_field('slideshare');
                echo do_shortcode('" .$slides. "'); ?>

I know this is incorrect but don't know how to amend it. Any pointers would be gratefully met!

closed as off-topic by kaiser Mar 5 '14 at 10:36

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

1

There's a general convention in WordPress:

  1. functions prefixed with the_ will echo a value
  2. functions prefixed with get_ or get_the_ will return a value

In your case you need to use get_sub_field() instead of the_sub_field() eg:

echo do_shortcode( get_sub_field( 'slideshare' ) );

The documentation on the ACF site is very comprehensive: http://www.advancedcustomfields.com/resources/functions/get_sub_field/

NOTE: In your example code you didn't need any of the quotes, you could've just passed in the $slides variable directly if you were using get_sub_field()

  • Thanks, that didn't quite work but with a little tinkering I got it... $slides = get_sub_field('slideshare'); echo do_shortcode('" .$slides. "'); – J_Mo Mar 6 '14 at 14:16

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