Cornerstone section being loaded at the beginning of the html body instead in the rigth place

Hi, I have another issue.

I created shortcode in functions.php:
add_shortcode(‘wpb_childpages’, ‘wpb_list_child_pages’);

Inside functions.php I have a function wpb_list_child_pages($atts) { } which basically checks for specific post types and shows the content. It echoes something like this (short version):

<div class="sometable>
   <div class="item">
      1st post title
   </div>
   <div class="item">
      2nd post title
   </div>
   <div class="item">
      3rd post title
   </div>
</div>

I’m using the shortcode inside the content area inside the col inside the row inside the section in the Cornerstone page editing (using [wpb_childpages]).

The shortcode works because I get the content. The issue is that when I’m editing the page I get the content shown inside the container in the right place (it’s like 3rd in a row, so I get the content nicely in the middle of the page). But when I go to see the page preview, all the content form this container starts showing in the browser top left corner.

I’m not using any special CSS (like absolute position or anything similar), so it’s really annoying. Anyone with any idea? Thanks :slight_smile:

Edit: to be accurate, the shortcoded content (whole div element) is seen in the top of the browser, but the element gets inserted right after div element with entry-content content class (it’s the div with ID parent-275 which should be nested quite lower in the code):
image

One other info that could help. I tried this code inside the content area:

<div class="testdiv">[wpb_childpages]</div>

Funny thing:

  • The DIV part of code was inserted inside the html content area (in the right place of the HTML code)
  • But the post summaries (their echo triggered by the shortcode) were again shown in the browser’s top

Am I doing something wrong with the shortcode?

Hi Boštjan,

Thanks for reaching out.
Although it is a custom coding related issue which is beyoond the scope of Theme Support, I would still curious to know the reason behind your issue. I would suggest you share the credentials for further investigation, but we can’t guarantee a fix on this.
please provide login credentials for your site in a secure note, including:

– WordPress Site URL & Login URL
– WordPress Admin username/password

To create a secure note, click the key icon underneath any of your posts.

Thanks

Secure note sent.

Hi Boštjan,

I have checked your code and found that it is echoing the content before returning. You need to return the content rather echoing. Your code should look like the following.

function wpb_list_child_pages($atts) 
{ 

    $str='<div id="parent-<?php the_ID(); ?>" class="workshops-table">';
        //you need to add all your output into the $str and return it.
    $str.='</div>';

    return $str;
}
add_shortcode('wpb_childpages', 'wpb_list_child_pages');

Hope it helps.
Thanks

Thanks makes sense. Will try it. Although it’s funny that it worked till recently :wink:

Hey Boštjan,

Great and let us know how it goes on your end!

Thank you.

Hey, it worked. Thanks for the hint :smiley:

Hi Boštjan,

Glad that we are able to help you.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.