Elementor displays the same shortcode twice (only on editor) Functions.php Two TIme Costom Post
Elementor displays the same shortcode twice. One in the place where the shortcode is placed, and the other right behind the header. The problem only occurs in the editor. On the page, it displays normally. Please help. How can i fix it?
I solved the problem :) I used ob_start(); and return ob_get_clean();
function elementor_shorcode_test() {
ob_start();
elementor_shorcode_test_output();
return ob_get_clean();
}
Example Code:/*Custom Post type start*/
function cw_post_type_events() {
$supports = array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'custom-fields', 'comments', 'revisions', 'post-formats', );
$labels = array(
'name' => _x('Events', 'plural'),
'singular_name' => _x('Event Post', 'singular'),
'menu_name' => _x('Event Post', 'admin menu'),
'name_admin_bar' => _x('event', 'admin bar'),
'add_new' => _x('Add New', 'add new'),
'add_new_item' => __('Add New event'),
'new_item' => __('New event'),
'edit_item' => __('Edit event'),
'view_item' => __('View event'),
'all_items' => __('All Events'),
'search_items' => __('Search event'),
'not_found' => __('No event found.'),
);
$args = array(
'supports' => $supports,
'labels' => $labels,
'public' => true,
'query_var' => true,
'rewrite' => array('slug' => 'event'),
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 5, );
register_post_type('event', $args);
}
add_action('init', 'cw_post_type_events');
/*Custom Post type end*/
// function that runs when shortcode is called
function wpb_demo_shortcode() {
ob_start();
?>
<style>
.wrapper {background: #040a46;}
.event .event-list {border: 2px solid #bb2392;margin-bottom: 10px;padding: 0 10px;display: flex; align-items: center;}
.event {width: 100%;}
.event .col.col-1 {width: 20%;}
.event .col.col-3 {width: 80%;padding: 10px;}
.event .col.col-1 img {width: 100%;height: 66px;object-fit: contain;}
.event h2, .event p, .event a {color: #fff;}
.event h2 {font-size: 22px;margin-bottom: 8px;}
p.date {font-size: 22px;}
.event p {font-family: "Jost", Sans-serif;font-family: "Jost", Sans-serif;font-size: 16px;}
a.book-now-event {
position: relative;
padding: 5px 14px 5px 14px;
background: transparent;
background-color: transparent;
background-image: linear-gradient(180deg, #C42091 0%, #6517C8 100%);
}
a.book-now-event:hover::before {width: 100%;}
a.book-now-event::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 50px;
height: 100%;
background: var(--e-global-color-accent);
border-radius: 100px;
transition: all 0.4s ease-in-out;
z-index: -1; }
@media only screen and (max-width: 500px) {
.event .col.col-1 {
width: 100%;
}
.event .event-list {
border: 2px solid #bb2392;
margin-bottom: 10px;
padding: 0 10px;
display: inline-block;
}
.event .col.col-1 {
width: 100%;
border-right: none;
text-align: center;
}
.event .col.col-3 {
width: 100%;
padding: 10px;
text-align: center;
}
}
</style>
<div class="wrapper">
<div class="event">
<?php
$args = array('post_type' => 'event', 'orderby' => 'date', 'order' => 'DESC' );
//print_r($args);echo '</pre>';
$the_query = new WP_Query($args);
if ($the_query->have_posts()) :
while ($the_query->have_posts()) :
$the_query->the_post();
$featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full');
?>
<div class="event-list">
<div class="col col-1">
<img src="<?php echo $featured_img_url; ?>" />
<p class="date"><?php
$value = get_field( "date" );
if( $value ) {
echo $value;
}
?></p>
</div>
<div class="col col-3">
<h2><?php echo get_the_title(); ?></h2>
<p><?php echo wp_trim_words(get_the_excerpt(), 7, ''); ?></p>
<p><img src="https://staging.vincentwolfe.com/wp-content/uploads/2025/06/location_o.png" /> <a href="<?php echo get_field( "location_link" ); ?>" class="book-now"><?php echo get_field( "location" ); ?></a></p>
<p><img src="https://staging.vincentwolfe.com/wp-content/uploads/2025/06/schedule__opsz.png" /> <?php echo get_field( "time" ); ?></p>
<a href="<?php echo get_field( "book_now_button" ); ?>" class="book-now-event">Book Now</a>
</div>
</div>
<?php endwhile;
wp_reset_postdata();
endif; ?>
</div>
</div>
<?php
return ob_get_clean();
}
// register shortcode
add_shortcode('events', 'wpb_demo_shortcode');
Comments
Post a Comment