Title: Nested echo php code
Last modified: July 19, 2020

---

# Nested echo php code

 *  [valerio](https://wordpress.org/support/users/valgo54/)
 * (@valgo54)
 * [6 years ago](https://wordpress.org/support/topic/nested-echo-php-code/)
 * Hello, I have a WP page with some links to click. Every time a link is clicked
   some images are displayed , each link clicked show different images. To do that
   I am using PHP to GET the link clicked. With plugin Insert PHP code snippet I
   manage the event after the link is clicked with the following:
 *     ```
       if(isset($_GET['link'])){
          $link=$_GET['link'];
          if ($link == '1'){
              $url1=  "http://localhost\Images\Site_Library\Standard\\"  . $img1 . ".png";
          }
          if ($link == '2'){
              $url2= ".\WpSito2\Images\Site_library_page\Standard\\" . $img2 . ".png";
          }
       }
       ```
   
 * I am in trouble when I try to echo the image related to link1 or link2 with the
   following code and short-code:
 *     ```
       <?php
       echo $url1
       ?>
       Shortcode [xyz-ips snippet="echo-url1"] 
   
       <div class="divi_1_psl" ><img class="img_psl" src="[xyz-ips snippet="echo-url1"]"></div> 
       ```
   
 * Surfing internet looking for a solution I didn’t solve.It’s seems that WP does
   not support netest code.
    Do you anyone have any idea in order to run nested 
   code or to have an alternative solution regarding my issue. Thanks in advance

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [6 years ago](https://wordpress.org/support/topic/nested-echo-php-code/#post-13141968)
 * What if you simply put the links to the images in the page from the start, instead
   of having to look it up when clicked?
    If you are writing PHP, you don’t need
   the plugin for the snippet shortcode. You can call the function directly. Shortcodes
   are for content areas where you can’t put PHP. They are expanded right before
   the content is output by the theme.
 *  Thread Starter [valerio](https://wordpress.org/support/users/valgo54/)
 * (@valgo54)
 * [6 years ago](https://wordpress.org/support/topic/nested-echo-php-code/#post-13143587)
 * HI Joy
    I need the links because different links give different images displayed.
   I did further tests: if in the snippet where I have
 *     ```
       if(isset($_GET['link'])){ 
       ```
   
 * I insert `global $url1` and I put `global $usrl1` in the snippet named `[xyz-
   ips snippet="echo-url1"]` as well, the echo command works. Unfortunately in the
   web site page I have
    `<img src="[xyz-ips snippet="echo-url1"]">` and the element
   src can contain only the echo command no other. Can you clarify me your point
   of view about “can call funcion directly” if this can help to fix this issue.
   Thanks
 *  Thread Starter [valerio](https://wordpress.org/support/users/valgo54/)
 * (@valgo54)
 * [6 years ago](https://wordpress.org/support/topic/nested-echo-php-code/#post-13146157)
 * Hi Joy,
    please do not consider previous post. I have done further test following
   your suggestion of functions.php. In that file I put the following:
 *     ```
       global $my_var;
       //$my_var="http://localhost/WpSito2/Images/Site_library_page/def_img.png"; both don't work
       $my_var=".\WpSito2\Images\Site_library_page\def_img.png";
       ```
   
 * Then in the php-snippet at the top of the WP page I put :
 *     ```
       global $my_var;
   
       if(isset($_GET['link'])) {
               $link=$_GET['link'];
               if ($link == '1'){
                $my_var=".\WpSito2\Images\Site_library_page\Standard\img1.png";
              }
       ```
   
 * In the Web page i have:
 *     ```
       	<div class="divi_1_psl" ><img class="img_psl" src="[xyz-ips snippet="echo-url1"]">
       ```
   
 * And in the [xyz-ips snippet="echo-url1]the content is:
 *     ```
       <?php
       echo $GLOBALS['$my_var'];
       ?>
       ```
   
 * So if in $my_var , in functions.php, I set a simple text e.g “Hello” and in the
   top-snippet I set $my_var=“Goodbye” ,when I load the Web page “Hello” is displayed
   and clicking the link , condition is $link=1, I see “Goodbye”.It works!But using
   image ,instead of the text, no! Do you have any idea in order to help in figure
   out this problem ?
    Many thanks
    -  This reply was modified 6 years ago by [valerio](https://wordpress.org/support/users/valgo54/).
 *  Moderator [tobifjellner (Tor-Bjorn “Tobi” Fjellner)](https://wordpress.org/support/users/tobifjellner/)
 * (@tobifjellner)
 * [6 years ago](https://wordpress.org/support/topic/nested-echo-php-code/#post-13146346)
 * [@valgo54](https://wordpress.org/support/users/valgo54/)
 * What are you trying to achieve? Right now, it’s unclear to me why you’re trying
   to do something very complicated that instead could easily be done with normal
   static HTML content.
 *  Thread Starter [valerio](https://wordpress.org/support/users/valgo54/)
 * (@valgo54)
 * [6 years ago](https://wordpress.org/support/topic/nested-echo-php-code/#post-13146927)
 * Hi,
    what I want to achieve is to click different links in order to display different
   images. I try to make a summary: In my web page I have 2 links.When I click link1
   in $my_var I should set image’s path 1, when I click link2 in $my_var I have 
   to set image’s path 2. What is it not running is the echo command that should
   run in a html content like this `<div class="divi_3_psl" ><img class="img_psl"
   src="<?php echo $my_var ?>"` Let me know if you need more details. Thanks
 *  [Dion](https://wordpress.org/support/users/diondesigns/)
 * (@diondesigns)
 * [6 years ago](https://wordpress.org/support/topic/nested-echo-php-code/#post-13147692)
 * PHP is server-side, and click-based actions are client-side. Looks to me like
   you should be using Javascript to accomplish your task.
 *  Thread Starter [valerio](https://wordpress.org/support/users/valgo54/)
 * (@valgo54)
 * [6 years ago](https://wordpress.org/support/topic/nested-echo-php-code/#post-13151547)
 * Hi ,
    ok per Javascript, do you have some advices/links I can follow ? Question:
   If I have in functions.php a define like this: `define("THEME_IMG_PATH","http://
   localhost/WpSite/Images");` and in WP page I have: `<div ><img src="<?php echo
   THEME_IMG_PATH; ?>/img1.png"></div>` Can the echo command display img1? I run
   a test but it doesn’t work. Thanks for your help

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Nested echo php code’ is closed to new replies.

 * In: [Localhost Installs](https://wordpress.org/support/forum/localhost-installs/)
 * 7 replies
 * 4 participants
 * Last reply from: [valerio](https://wordpress.org/support/users/valgo54/)
 * Last activity: [6 years ago](https://wordpress.org/support/topic/nested-echo-php-code/#post-13151547)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
