Title: format_to_post
Last modified: August 18, 2016

---

# format_to_post

 *  [dissurion](https://wordpress.org/support/users/dissurion/)
 * (@dissurion)
 * [21 years, 6 months ago](https://wordpress.org/support/topic/format_to_post/)
 * This hook gives me some problems. Whatever I try to do with it for modifying 
   the post data (I alter it before sending it to the database, or I would like 
   to), it gives me a ‘headers already sent’ error.
    I just have a simple funtion,
   that I register using add_filter with format_to_post.

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Anonymous
 * [21 years, 6 months ago](https://wordpress.org/support/topic/format_to_post/#post-114401)
 * I use it and it works fine for me. Are you sure you don’t send any output from
   your plugin? Spaces at the beginning of your file etc.
 *  Thread Starter [dissurion](https://wordpress.org/support/users/dissurion/)
 * (@dissurion)
 * [21 years, 6 months ago](https://wordpress.org/support/topic/format_to_post/#post-114403)
 * > Are you sure you don’t send any output from your plugin?
 * Now I’m pretty sure I use it wrong.
    I thought I should output something, eg 
   get the post data and echo what I want. But if this is a wrong usage, how do 
   I get this result? ps: thanks for the reply
 *  [joh](https://wordpress.org/support/users/joh/)
 * (@joh)
 * [21 years, 6 months ago](https://wordpress.org/support/topic/format_to_post/#post-114470)
 * `format_to_post` is meant for filtering the posted content before it is saved
   to the database. As soon as you echo something in this hook, this will go out
   way before anything else is sent to the browser, breaking the page.
    Note that
   this is basically the same with all filter hooks. Every function you hook in 
   there is passed some variable and has to return it (maybe with altered content).
   Echo anything and it will happen at a point in the program flow that will quite
   surely break your site. Maybe you should explain a bit more clear what you want
   to do?
 *  Thread Starter [dissurion](https://wordpress.org/support/users/dissurion/)
 * (@dissurion)
 * [21 years, 6 months ago](https://wordpress.org/support/topic/format_to_post/#post-114612)
 * What I want to do is take the post input, intercept it, add/change something 
   to it, let it go it’s normal flow. 🙂 So basically add/change something to it
   and get that in the database, or change it before it is send to the database.
 *  [joh](https://wordpress.org/support/users/joh/)
 * (@joh)
 * [21 years, 6 months ago](https://wordpress.org/support/topic/format_to_post/#post-114839)
 * Then `format_to_post` is exactly what you need. When you get a ‘headers already
   sent’ error this means your function is echoing something. The function you hook
   into the filter shouldn’t echo anything, it should _return_ the data as in `return
   $content;`, not `echo $content;`.
    Or you have whitespace before `<?php` or after
   the closing `?>` in your plugin. Note that the plugins are loaded before anything
   is sent to the browser and if a plugin echoes data WP can’t sent HTTP-headers
   anymore.
 *  Thread Starter [dissurion](https://wordpress.org/support/users/dissurion/)
 * (@dissurion)
 * [21 years, 6 months ago](https://wordpress.org/support/topic/format_to_post/#post-114859)
 * Thanks for the help. Now I got it working. 🙂

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘format_to_post’ is closed to new replies.

 * 6 replies
 * 3 participants
 * Last reply from: [dissurion](https://wordpress.org/support/users/dissurion/)
 * Last activity: [21 years, 6 months ago](https://wordpress.org/support/topic/format_to_post/#post-114859)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
