Back to Top

Solution: Shortcode move to top of content issue

Solution: Shortcode move to top of content issue

Recently I was working with one of application and I have created shortcode for some functionality and I want to display shortcode data after the content of posts so I have place shortcode after the post content from admin editor.

But in frontend, shortcode data was displaying in top of content even I put shortcode anywhere in editor, It displays top of page so today I am going to share how I solve issue of it

You should check out this ShortCode in WordPress to learn everything about Shortcode in WordPress with examples

I have used ob_start and ob_get_clean function to clear the buffer and it starts working. That will return the content rather than echo it directly and that you have to do in the case of a WordPress shortcode

Solution

if ( ! function_exists( 'change_background_color' ) ) {
    function change_background_color( $atts ) { 
       ob_start();
       $attributes = shortcode_atts( array(
                                 'id' => 'value',
                    ), $atts );
       // your desired code
      return ob_get_clean();
   }
}

This works for me like a charm. Hopefully works for you also. Please share this article if this works for you.Solution: Shortcode moves to the top of the content issue.

You may also like:

Programmatically Insert Content in WordPress
SSL with WordPress
Create Own Widget in WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How to add custom post type in RSS Feed?

Posted on 5 years ago

Bhumi

An Introduction to Kubernetes

Posted on 3 years ago

Bhumi

How to Import Users in MODx from CSV file

Posted on 6 years ago

Bhumi

To Swap Database Row in PHP

Posted on 7 years ago

Bhumi

Storing Objects in Html5 Local Storage

Posted on 2 years ago

Bhumi

Hello world

Updated 1 week ago

Nick Carter

In depth Understanding of Laravel Core

Updated 2 months ago

Bhumi

ECMAScript 6 New Features – 2

Updated 1 year ago

Bhumi

The Reader’s Poll – June 2015

Posted on 4 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 4 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 5 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 5 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 5 years ago

Bhumi