0

Hello wordpress developers.

I have created a plugin that allows me to insert content on a page by using a shortcode, the content is rather long since it is an list of data. When editing the page with elementor, i get "duplicate" view since it shows an "preview" of the content from the shortcode above the editor.

Is there any way to disable the preview, either from the code or the backend? From the plugin, i make the shortcode available like this:

add_shortcode('apartmentList', function() {
     include 'ApartmentLists/ApartmentListOne.php';
});

1 Answer 1

0

Always use output buffers with shortcode to ensure the content is captured and displayed only where shortcode is used. So your code will get modified as follows:

add_shortcode('apartmentList', function() {
     ob_start();
     include 'ApartmentLists/ApartmentListOne.php';
     return ob_get_clean();
});

Also, if you are looking to stop the display of the shortcode content completely on the Elementor Editor, you can add a simple condition as follows:

add_shortcode('apartmentList', function() {
     // Check if Elementor is rendering the backend
     if (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] === 'elementor') {
         return ''; // Return an empty string in the Elementor editor
     }

     ob_start();
     include 'ApartmentLists/ApartmentListOne.php';
     return ob_get_clean();
});

is_admin() will check if the page is a backend page.

$_REQUEST['action'] === 'elementor' will check if the Elementor Editor is active.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.