I was working on a WordPress plugin, and I found that when the_content filter hook is used, it gives content of t开发者_StackOverflow社区he 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
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;
}
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.
精彩评论