tags:

views:

113

answers:

2

Hello guys,

I was working on a WordPress plugin, and I found that when the_content filter hook is used, it gives content of the post to the function as a parameter, but in plain-text format. I want to get the HTML content of the post, any way to achieve this?

Thanks - Kapeel

A: 

Do you have any plugins installed, or are you filtering the_content elsewhere?

By default, the content passed through the filter the_content is pretty much what's in the database, minus a bit of parsing (handling <!-- more --> teasers etc.).

Are you sure that the post content does actually contain HTML? Don't forget WordPress will add paragraphs on-the-fly, and won't necessarily store them in the DB.

TheDeadMedic
I tried disabling all the plugins but it didn't work. :-(
KPL
Have you checked the contents of your DB - is WordPress definitely stripping HTML, or is real the problem that there isn't any HTML stored?
TheDeadMedic
A: 

Finally, after searching a lot, I had solved it.

As said by TheDeadMedic - "Are you sure that the post content does actually contain HTML? Don't forget WordPress will add paragraphs on-the-fly, and won't necessarily store them in the DB."

WordPress does by using a function called wpautop();

I just used this with get_the_content(); , and I got it working.

Here's an example of how you can achieve this -

function myPluginReplaceContent() {
    $content    =   wpautop(get_the_content());
    $content    .=  myPluginGetData(); // do whatever you want to - here
    return $content;
}

EDIT :

I found that this function won't apply filters by other plugins. The following function won't cause any issues.

function myPluginReplaceContent($thecontent) {      
    $thecontent .=  myPluginGetData(); // do whatever you want to - here
    return $content;
}
KPL