• Resolved ransom1337

    (@ransom1337)


    Hello,

    I have been editing functions.php to customise my comments section, and the styling is working fine, however now whenever someone posts a comment, the following error comes up:

    Warning: Cannot modify header information – headers already sent by (output started at /blog/wp-content/themes/ransom/functions.php:442) in /blog/wp-includes/pluggable.php on line 890

    I haven’t tampered with pluggable.php at all, but here is line 442 of functions.php, which is where I’ve been working on the custom comment:

    <?php //this function will be called in the next section
    function advanced_comment($comment, $args, $depth) {
       $GLOBALS['comment'] = $comment; ?>
    
    <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
    <div class="comment_post_wrap">
       <div class="comment_post_left">
         <?php echo get_avatar($comment,$size='100',$default='<path_to_url>' ); ?><br />
           <a href="<?php the_author_meta( 'user_url'); ?>"><?php printf(__('%s'), get_comment_author_link()) ?></a><br />
           <?php printf(get_comment_date()) ?>
       </div>
    
         <?php if ($comment->comment_approved == '0') : ?>
           <em><?php _e('Your comment is awaiting moderation.') ?></em>
           <br />
         <?php endif; ?>
    
         <div class="blog_post_right">
             <?php comment_text() ?>
         </div>
         </div>
    </li>
    <div class="comment_divider"></div>
    
    <?php } ?>

    How would I correct the problem? Any ideas why it’s happening?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Try removing the spaces between “?>” and the content following each case of “?>”

    I.e.

    <?php //this function will be called in the next section
    function advanced_comment($comment, $args, $depth) {
    $GLOBALS[‘comment’] = $comment; ?>

    <li <?php comment_class(); ?> id=”li-comment-<?php comment_ID() ?>”>
    <div class=”comment_post_wrap”>

    Would become

    <?php //this function will be called in the next section
    function advanced_comment($comment, $args, $depth) {
    $GLOBALS[‘comment’] = $comment; ?><li <?php comment_class(); ?> id=”li-comment-<?php comment_ID() ?>”><div class=”comment_post_wrap”>

    From problems I have with that, it should work.

    Hope that helps,

    Jason

    I copied your block of code above into my functions.php and replaced my callback function with that, and it all worked fine. I think your error is elsewhere in your functions.php (Maybe an open bracket or something earlier in the file?)

    The most common causes of the ‘headers already sent‘ error in php are:

    – Output of some sort before the first ‘<?php’ tag in a file, this includes white space and in my experience the UTF-8 BOM character, so save all php files in ANSI format.

    – Any output (i.e. echo, print or whitespace(tabs)) before the session_start() command.

    – Attempts to process an output request after output has started, when not using php’s output buffer ob_start(). See here

    hth

    Happended to me once, solved deleting empty lines before the first written line in the document.

    Thread Starter ransom1337

    (@ransom1337)

    Wow. Yeah I had a bunch of empty lines just above the function just so I could see it more clearly, separated from the rest of the functions. But yup, deleting the lines fixed it! Thanks guys.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Cannot modify header information – headers already sent’ is closed to new replies.