Support

Account

Home Forums Backend Issues (wp-admin) my functions.php breaks Elementor and gives "cannot modify header…"

Solved

my functions.php breaks Elementor and gives "cannot modify header…"

  • Hi! I have created a function in my functions.php that returns the values of my ACF custom fields to a shortcode. The Frontend is working nicely but i’m getting an error “Warning: Cannot modify header information – headers already sent…” and elementor editor is not loading any more.
    I might have messed up the ob get clean (); part, I dont know. Maybe someone can help me find my mistake? Here’s my function:

    function additional() {
    ob_start();
    $args = array('post_type' => 'additional_infos_by_',  'orderby' => 'title','order'   => 'ASC',  'posts_per_page' => '20',);
    $the_query = new WP_Query( $args );
    ?>
    <div class="table">
    <?php
    while ( $the_query->have_posts() ) : $the_query->the_post();
    $fields = get_fields();
    if( $fields ): ?>
    <div id="<?php the_field('country_shortcode'); ?>" class="cell title table-row country-<?php the_field('nation'); ?> country-additional">
    <div id="country_<?php the_field('nation'); ?>" ><?php the_field('nation'); ?><br /></div>
    </div>       
    <?php 
            endif; 
            endwhile;
            wp_reset_postdata(); 
            wp_reset_query();	
            return ob_get_clean();
      }
    ?> 
    </div>
    <?php
    add_shortcode( 'additional_infos', 'additional' );
    ob_get_clean();

    I have checked the forums and found that there cant be any blank spaces before opening <?php but there are no blank spaces. So i guess my function is messing up the system. I hope someone can point me to my mistake. Thanks!
    Zvenson!

  • I found the solution – i cant use <?php and ?> in my code – need to use
    echo ‘</div>’; to insert html in my function.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.