Skip Navigation

[Resolved] Custom Shortcode positioning

This thread is resolved. Here is a description of the problem and solution.

Problem: I have written a custom shortcode that should echo information inside the View's loop, but it is written out before the loop.

Solution: Use output buffering, or return a text string in your shortcode. It is not recommended to echo directly in the shortcode.

Relevant Documentation:
https://wpshout.com/php-output-buffering/
https://codex.wordpress.org/Shortcode_API

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by puneetS-3 5 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#1305525
Screenshot (11).png

Tell us what you are trying to do?

I have written a custom short which I am rendering inside .
<wp-loop>

</wp-loop>

Everything is working fine but its the way it is rendering on the front-end is the problem.

This is my view code:

		<wpv-loop>
          <div>
            <p>  id: [wpv-post-id] School-name: [school_names order="[wpv-post-id]"]
            [order_amount order="[wpv-post-id]"]
            </p>
          </div>
		</wpv-loop>

This is how it is being rendered on the front-end: (image attached)

<div class="page-content">
		Parevartan School02019-07-31T11:39:18+00:00Parevartan School02019-07-31T08:34:51+00:00                <div class="container-fluid ">
                <div class="ddl-full-width-row row ">
                <div class="col-sm-10 col-sm-offset-1">





<div id="wpv-view-layout-1580-CATTR3579443b48509f35ac4f8e0f6629c39eTCPID1680" class="js-wpv-view-layout js-wpv-layout-responsive js-wpv-view-layout-1580-CATTR3579443b48509f35ac4f8e0f6629c39eTCPID1680" data-viewnumber="1580-CATTR3579443b48509f35ac4f8e0f6629c39eTCPID1680" data-pagination="{"id":"1580","base_permalink":"/parent-orders/?wpv_view_count=1580-CATTR3579443b48509f35ac4f8e0f6629c39eTCPID1680&wpv_paged=WPV_PAGE_NUM","query":"normal","type":"disabled","effect":"fade","duration":500,"speed":5,"pause_on_hover":"disabled","stop_rollover":"false","cache_pages":"enabled","preload_images":"enabled","preload_pages":"enabled","preload_reach":1,"spinner":"builtin","spinner_image":"<em><u>hidden link</u></em>","callback_next":"","manage_history":"enabled","has_controls_in_form":"disabled","infinite_tolerance":"0","max_pages":0,"page":1,"loop":{"type":"","name":"","data":[],"id":0}}" data-permalink="/parent-orders/?wpv_view_count=1580-CATTR3579443b48509f35ac4f8e0f6629c39eTCPID1680">

	
	
		
          <div>
            <p>  id: 1695 School-name: 
            
            </p>
          </div>
		
          <div>
            <p>  id: 1687 School-name: 
            
            </p>
          </div>
		
	
	
	
</div>


<div id="wpv-view-layout-1689-TCPID1680" class="js-wpv-view-layout js-wpv-layout-responsive js-wpv-view-layout-1689-TCPID1680" data-viewnumber="1689-TCPID1680" data-pagination="{"id":"1689","base_permalink":"/parent-orders/?wpv_view_count=1689-TCPID1680&wpv_paged=WPV_PAGE_NUM","query":"normal","type":"disabled","effect":"fade","duration":500,"speed":5,"pause_on_hover":"disabled","stop_rollover":"false","cache_pages":"enabled","preload_images":"enabled","preload_pages":"enabled","preload_reach":1,"spinner":"builtin","spinner_image":"<em><u>hidden link</u></em>","callback_next":"","manage_history":"enabled","has_controls_in_form":"disabled","infinite_tolerance":"0","max_pages":0,"page":1,"loop":{"type":"","name":"","data":[],"id":0}}" data-permalink="/parent-orders/?wpv_view_count=1689-TCPID1680">

	
	
		<strong>No items found</strong>
	
</div>
</div></div></div>		<div class="post-tags">
					</div>
			</div>
#1305669

Hi, usually this type of break happens when a shortcode's output isn't buffered, or echos text directly. Are you using WordPress's output buffering functions in your shortcode? Is the shortcode designed to return text, or echo text?
https://wpshout.com/php-output-buffering/
https://codex.wordpress.org/Shortcode_API

#1306563

My issue is resolved now.I was using echo. Thank you!