0

I'm trying to use an image for my title using the jQuery Collapse-O-Matic plugin, however I am using the do_shortcode echo and am stumbling a bit on how to add an echo within an echo. I've tried a few options including the Heredoc method but I am not sure how to implement with my particular code.

I've added my code below, can anyone point me in the right direction? All and any help is appreciated, thanks!

<?php echo do_shortcode('[expand title="<img src='<?php echo get_template_directory_uri(); ?>/img/schedule.png' />" trigpos="below"]this is content..this is content..this is content..this is content..this is content..this is content..this is content..this is content..this is content..this is content..this is content..[/expand]'); ?>
1
  • 1
    that'll never work. echo performs output immediately. you probably do do_shortcode('...' . get_template_director() . '...') instead. No echo at all. just call the function and concatenate the results. Commented Jul 7, 2014 at 16:58

2 Answers 2

6

You don't need to use echo inside the <img> tag. The string returned by get_template_directory_uri() will be concatenated. Use this code:

<?php echo do_shortcode('[expand title="<img src=\''.get_template_directory_uri().'/img/schedule.png\' />"

Edit: For more information refer to Strings in the manual. In this case you can think about the function call like a variable. You could write the code this way:

$uri = get_template_directory_uri();
echo '<img src=\''.$uri.'/img/schedule.png\' />';

But instead of using a variable, you can call the function directly in the echo statement.

echo '<img src=\''.get_template_directory_uri().'/img/schedule.png\' />';

This statement can be divided into three parts:

  • '<img src=\'': This is a string literal.
  • get_template_directory_uri(): This is a function which returns a string.
  • '/img/schedule.png\' />': This is another string literal.

The dots (.) concatenate these three parts into a string which is then printed by echo. See String Operations for more details.

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome, huge help! Thank you for the lesson, learned a lot here!
1

Try this:

<?php echo do_shortcode('[expand title="<img src=\''. get_template_directory_uri() .'/img/schedule.png\' />" trigpos="below"]this is content..this is content..this is content..this is content..this is content..this is content..this is content..this is content..this is content..this is content..this is content..[/expand]'); ?>

1 Comment

Awesome, thanks guys! I had to remove the second single quote after the image but that did the trick! Is this just a form of "minimizing" php? I am no PHP expert so I really appreciate all the help, self teaching over here! :)

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.