Title: Shortcode Putting html in parent div
Last modified: August 20, 2016

---

# Shortcode Putting html in parent div

 *  [mortalwombat](https://wordpress.org/support/users/mortalwombat/)
 * (@mortalwombat)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/shortcode-putting-html-in-parent-div/)
 * This one has me really confused.
 * I have built two shortcode objects. When I insert them into a page, the output
   of the shortcode function is going into it’s parent’s parent div.
 * So for example we will use the shortcode I created which slaps in some simple
   HTML to include a slideshow of images. My HTML will look something like this:
 *     ```
       <div id="primaryContent">
         <div id="post-1436" class="postWrapper">
          <div class="page_content">
           <div class="entry">
             (Slideshow and other page content should go here)
           </div>
          </div>
         </div>
        </div>
       ```
   
 *  When I edit the page through admin, I can put something that looks like this:
 *     ```
       Test
       [slideshow]
       ```
   
 * Here’s where things don’t work properly though. The “Test” Text goes into the“
   entry” div where it should, but slideshow gets dumped into the “postwrapper” 
   div, just above the “page_content” div.
 * Why isn’t the code that’s being dynamically entered going where it belongs, but
   anything that is typed directly into the admin panel goes wehre it should? Beats
   me!

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/shortcode-putting-html-in-parent-div/#post-2710794)
 * Perhaps you need to re-examine your shortcode callback functions and ensure that
   you are returning – not echoing – the result?
 *  Thread Starter [mortalwombat](https://wordpress.org/support/users/mortalwombat/)
 * (@mortalwombat)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/shortcode-putting-html-in-parent-div/#post-2710800)
 * Hmm…
 * One of the shortcode functions just includeds a php file that has some very basic
   HTML in it. This is one of the ones that is messing up.
 * One of the other shortcodes is echoing instead of returning. (I’m not really 
   aware of the difference, but I will research that since clearly it’s important)
 *  Thread Starter [mortalwombat](https://wordpress.org/support/users/mortalwombat/)
 * (@mortalwombat)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/shortcode-putting-html-in-parent-div/#post-2710802)
 * OK, so changing echo to return worked for the slideshow gallery. Thanks!
 * However, the one that includes a php file with HTML in it is still having troubles.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/shortcode-putting-html-in-parent-div/#post-2710805)
 * Can you turn that php file into a string and return the string?
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/shortcode-putting-html-in-parent-div/#post-2710808)
 * HTML gets echoed automatically
    – to prevent this you need to put the html into
   a string and concatenate the strings as they are generated – then return the 
   full string.
 * if you need help with understanding the principle, paste the full code of the
   shortcode with the html into a [http://pastebin.com/](http://pastebin.com/) and
   post the link to it here – see [http://codex.wordpress.org/Forum_Welcome#Posting_Code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)
 *  Thread Starter [mortalwombat](https://wordpress.org/support/users/mortalwombat/)
 * (@mortalwombat)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/shortcode-putting-html-in-parent-div/#post-2710826)
 * [My functions.php](http://pastebin.com/JLDthDAW) (Note to esmi, return doesn’t
   allow any LI’s to get created, which leaves me with a blank slideshow)
 * [My single.php](http://pastebin.com/PzfKvYe0) file that is creating the issue
 * And lastly, [the HTML that is currently being output](http://pastebin.com/1cZME1Ck)
 * Thank you guys so much for your help. I clearly need to learn a few things 🙂
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/shortcode-putting-html-in-parent-div/#post-2710831)
 * What’s wrong with using:
 *     ```
       function start_slider() {
               $photos = slider_get_images(); $output = '';
               if ($photos) {
                       $output.= '<div class="slideshow"><div class="slideContainer"><ul class="slides">';
                       foreach ($photos as $photo) {
                               $output.= '<li class="photo">' . $photo . '</li>';
                       }
                       $output.= '</div></ul></div>';
               }
        	return $output;
        }
       ```
   
 *  Thread Starter [mortalwombat](https://wordpress.org/support/users/mortalwombat/)
 * (@mortalwombat)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/shortcode-putting-html-in-parent-div/#post-2710839)
 * Absolutely nothing wrong with that! It works great. I didn’t know I had to do
   that though. What I don’t understand is why echo has the results that it does,
   and why return works better. I understand the fundamental difference between 
   echo and return, but didn’t know it could create issues like that.
 * Can you explain the problem behind echo?
 *  Thread Starter [mortalwombat](https://wordpress.org/support/users/mortalwombat/)
 * (@mortalwombat)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/shortcode-putting-html-in-parent-div/#post-2710847)
 * For my upperfooter.php, I have the file as an include so I can easily edit the
   one file should I choose to make a change going forward. I can have that in the
   functions.php, but it seems more organized to have a seperate php file for the
   code that makes up the upper footer. What would be the best way to accomplish
   that since include doesn’t work?
 *  Thread Starter [mortalwombat](https://wordpress.org/support/users/mortalwombat/)
 * (@mortalwombat)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/shortcode-putting-html-in-parent-div/#post-2710986)
 * Yup, I am still stuck. I feel like there is something fundamental I am missing
   here. I have created a function for my Upper Footer, and it puts everything where
   I want it except for one small thing. I am using `bloginfo("template_url")` to
   get the path to the images inside my template. It outputs the results of the 
   template_url outside of the div, and puts the rest where it belongs, which results
   in a text display of the path the to template outside the div, and broken links
   inside the div. [Here is my code](http://pastebin.com/JeeFq6Du).

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

The topic ‘Shortcode Putting html in parent div’ is closed to new replies.

## Tags

 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 10 replies
 * 3 participants
 * Last reply from: [mortalwombat](https://wordpress.org/support/users/mortalwombat/)
 * Last activity: [13 years, 11 months ago](https://wordpress.org/support/topic/shortcode-putting-html-in-parent-div/#post-2710986)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
