Why is shorcode showing in front end but Elementor not loading it?

I have this shortcode which is normally ok, it's showing well on the front end.

<?php

add_shortcode('slider-vehicules', 'slider_vehicules_shortcode');
function slider_vehicules_shortcode(){
    ob_start();
    ?>
    <div class="slider-vehicules">
    <?php

    $args = array(
        'post_type' => 'vehicules',
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'orderby' => 'date',
        'order' => 'ASC'
    );

    $the_query = new WP_Query( $args );

    if ( $the_query->have_posts() ) {
        while ( $the_query->have_posts() ) : $the_query->the_post();
            echo '<h3>'.get_the_title().'</h3>';
        endwhile;
    }

    ?>
    </div>
    <?php
    return ob_get_clean();

When I try to open the page where I put the shortcode I get this error.

enter image description here

Anyone knows how to fix this?

Thank you !

Upvotes: 1

Views: 44

Answers (1)

Lajos Arpad
Lajos Arpad

Reputation: 76564

Please refer to this page: https://elementor.com/help/the-content-area-was-not-found-error/

This error message usually appears in the following scenarios:

- When Trying to edit an archive page without creating an archive template / not editing through the archive template.
- When using an incompatible theme or plugin
- When the website URL and home page URL are not the same

The page continues, with stating that we need to determine whether this happens on all pages or only on a specific page.

enter image description here

enter image description here

enter image description here

Summary

As the error message tells you, there is an expectation according to which the_content() needs to be called by the template. It's a normal expectation, because there is not much use to display the frame if the content is missing. You therefore need to call this function at some place and Elementor's magical features under the hood are making sure that it is called. Yet, if the template is damaged somehow (an uninitiated programmer may have had an idea to improve it or so), or you create a custom template, it's possible that the call to this function is not added, not properly added, or even removed. It's also possible that it's only conditionally called (such as the case when you only display your content to logged in or high-privileged users) and thus you get this error when such a condition is not met. In short: you will need to look into the cause for missing the call to this function and use it either using some Elementor (UI or other) features, or look into the code and call this function.

Upvotes: 0

Related Questions