Solved

PHP echo single quote breaking echo

Posted on 2011-09-30
5
392 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 110

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 110

Expert Comment

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

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finallā€¦
This article discusses how to implement server side field validation and display customized error messages to the client.
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchiā€¦
The viewer will learn how to dynamically set the form action using jQuery.

695 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