Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to add a little form after each post for a plugin I have to code, but I'm not very familiar with Wordpress. By using add_action with the_content as hook, I was able to add some text to the content.

My trouble is that the whole text stored in the $content variable seemed to be processed somehow. Specifically, there is a br/ added after each of my input fields, which break the layout of my form. I noticed that I don't have this issue if I had my form right before the comment form, for instance. But I don't want to put my form here, I need it to be really just after the post itself, prior to anything related to comments.

Is there a way to disable this text and html formatting, but only for the form I'll be adding to the content ? In case there is no easy way to do so, I've tried finding a hook that would allow me to add something AFTER the content and BEFORE the comments to do so, but had no luck finding one. Is there such a hook ?

share|improve this question

2 Answers 2

You'll actually want to filter the content, not use an action. You could wrap your form in the output buffer and append it onto to it, like so:

function my_content_filter($content) {
    ob_start(); 

    // your form here

    $form = ob_get_clean();

    if (get_post_type() == 'post')
        return $content . $form;

    return $content;
}
add_filter('the_content', 'my_content_filter');

Let me know if that helps.

share|improve this answer

If I understand what you are doing, and the problem you are having, the first thing I'd try is to add your the_content filter with a large priority number so that it runs late, and hopefully after the other formatting filters.

add_filter('the_content','your_callback',100);

If that doesn't do it you may have to remove and reorder some some filters.

If this is a page and you can edit the template for that page, you could also run get_the_content, apply the content filters to it, then append your form before you echo.

$content = get_the_content();
$content = apply_filters('the_content',$content);
$content = $content.$your_form;
echo $content;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.