tags:

views:

23

answers:

2

Warning: Cannot modify header information - headers already sent by (output started at /home/content/51/5126851/html/wp-includes/post-template.php:54) in /home/content/51/5126851/html/wp-includes/pluggable.php on line 890

I know I need to do something to my post-template.php file, but I'm not sure what. I looked at the other answers but mine seems a little different. Here's what the relevant function looks like:

/**
 * Display or retrieve the current post title with optional content.
 *
 * @since 0.71
 *
 * @param string $before Optional. Content to prepend to the title.
 * @param string $after Optional. Content to append to the title.
 * @param bool $echo Optional, default to true.Whether to display or return.
 * @return null|string Null on no title. String if $echo parameter is false.
 */
function the_title($before = '', $after = '', $echo = true) {
    $title = get_the_title();

    if ( strlen($title) == 0 )
        return;

    $title = $before . $title . $after;

    if ( $echo )
        echo $title; // <-- This is line 54 of post-template.php
    else
        return $title;
}
+3  A: 

My first recommendation would be to learn how to format code for SO. And figure out how to cut down your problem to the bare minimum someone needs to solve it.

My second would be to look around the line mentioned in the error. I just did, and look what I found:

if ( $echo )
    echo $title;

So now you know what's outputting stuff, what can you do about it?

Well, the other part of that statement is:

else
    return $title;

Now, I'm no Wordpress expert, but I'm sure that you can work out the first thing that needs changing.

Anon.
I'm not sure, I really have very little experience with this. Should it be then $title instead of echo $title?
Daniel
@Daniel There's a boolean flag being passed to the function named `$echo`, which defaults to true -- if it's true the title is echoed. Since you don't want the title echoed (echoing something sends the headers, which is causing your problem), pass `false` for the `$echo` flag when calling that function
Michael Mrozek
@Anon. He shouldn't be mucking about in core code anyways.
ceejayoz
so it should be if ( $echo )echo false;??
Daniel
@ceejayoz: I realize that. My answer was hinting towards "set $echo to false" in the config or wherever it's supposed to be modified, not towards hacking up the WP core.
Anon.
@Daniel No. There's a call to `the_title` somewhere else that doesn't pass a third argument (or passes `true`); you need to change it so the third argument is `false`. ceejayoz is right though, it seems like you shouldn't need to change this; you might want to [edit your question](http://stackoverflow.com/posts/3136381/edit) to describe what you're trying to do/how you caused this instead
Michael Mrozek
+1  A: 

You shouldn't be editing files in wp-includes without a good reason and a good understanding of what you're doing. WordPress is extendable via themes and plugins in almost all situations - you should rarely, if ever, have to hack core code to do something.

ceejayoz
So what do you suggest?
Daniel
I suggest restoring your WordPress files to the core default. This error doesn't appear in a stock install. It would be helpful to know what version of WordPress, too.
ceejayoz