• 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)
  • Perhaps you need to re-examine your shortcode callback functions and ensure that you are returning – not echoing – the result?

    Thread Starter mortalwombat

    (@mortalwombat)

    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

    (@mortalwombat)

    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.

    Can you turn that php file into a string and return the string?

    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/ and post the link to it here – see http://codex.wordpress.org/Forum_Welcome#Posting_Code

    Thread Starter mortalwombat

    (@mortalwombat)

    My functions.php (Note to esmi, return doesn’t allow any LI’s to get created, which leaves me with a blank slideshow)

    My single.php file that is creating the issue

    And lastly, the HTML that is currently being output

    Thank you guys so much for your help. I clearly need to learn a few things 🙂

    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

    (@mortalwombat)

    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

    (@mortalwombat)

    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

    (@mortalwombat)

    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.

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

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