Solved

PHP echo single quote breaking echo

Posted on 2011-09-30
5
385 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 17

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 109

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 109

Expert Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

832 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