Solved

PHP echo single quote breaking echo

Posted on 2011-09-30
5
379 Views
Last Modified: 2012-05-12
I am trying to use a dynamic variable in a Wordpress shortcode in a theme using do_shortcode like this:

<?php echo do_shortcode('[map id="map1" address="<?php echo($row['fulladdress']); ?> <?php echo($row['city']); ?>, <?php echo($row['zip']); ?> " z="15"]'); ?>

Open in new window


That does not work...this does though so I know its my echo statements breaking it because this does work:

<?php echo do_shortcode('[map id="map1" address="Austin, TX " z="15"]'); ?>

Can someone help me figure out how to format this?
0
Comment
Question by:pda4me
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:Chris Harte
ID: 36893158
I don't know anything about wordpress or do_shortcode, but I can tell you have a lot of mismatched braces and brackets in there. Do not echo variables or use  php tags inside php tags. That z=15 is just hanging loose on the end of that line. I can not tell what you are trying to do with it. But try this.


$content = '[map id="map1" address="'.$row['fulladdress'].'"';

echo do_shortcode ($content);


echo($row['city']);
echo($row['zip']);
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 36893218
Using echo inside echo seems out of place to me.  And echo is not a function so you can remove the parentheses.

I think you might be looking for something like this, but it is hard to guess:

$str = '[map id="map" address="';
$str .= $row['fulladdress'];
$str .= '"';
$str .= ' ' . $row['city'];
$str .= ' ' . $row['zip'];
$str .= '"'
$str .= '  z="15"]';

echo do_shortCode($str);

It is much easier to get the code right if you do not use compound statements.
0
 

Author Comment

by:pda4me
ID: 36893225
i need the city and zip and the closing bracket ] to finish the short code?  How do I include those?  Nothing I try worked?
0
 

Author Closing Comment

by:pda4me
ID: 36893278
Bingo, thanks Ray!!!
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 36893304
Thanks for the points!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

WordPress can be pretty daunting, especially for a beginner, so I thought it might be a good idea to write an article to show how easy it is to get started in WordPress and to design a custom theme.  The first step is to check with your hosting comp…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now