I am using a plugin called AddThis on a website at: http://minionsphotography.com/. With AddThis enabled I am getting some extra P tags in-between the header and the text on the page: <p><!-- AddThis Sharing Buttons above --></p>, this adds a lot of extra space and shouldn't be there. *On the homepage it's the space between the Welcome header and the slideshow image.

Is there a function or something out there that I could use to find and remove the html comment on the page to eliminate the extra space? I use a plugin called pSquirrel to detect and remove empty P tags, but it won't remove this one (I'm guessing because pSquirrel doesn't think it's empty because of the html comment).


  • I can't see anything like you mentioned in your website. Can you please add a screenshot?
    – Johansson
    Commented Jun 6, 2017 at 14:27

2 Answers 2


You put this function there:

$("#main").each(function() {
                var text = $(this).text();
                text = text.replace("<p><!-- AddThis Sharing Buttons above --></p>", "");

Did it work?

If not, why do you want to do that? You can go to the main plugin and replace this text..

  • Hey there, nope, unfortunately not...I try not to modify plugins, so I figured a little jQuery would do the trick, but for some reason I was mistaken. The reason why I want to is simple, because of the amount of space between the header and the text...and honestly it shouldn't be there. Now on several other sites this is not happening with the AddThis plugin, so I'm really not sure why I'm seeing it here. Commented Jun 6, 2017 at 18:29

I added this to my functions.php file, which removes all html comments, which eliminates the issue.

I found the solution here: https://www.thewebtaylor.com/articles/wordpress-remove-html-comments

function callback($buffer) {
    $buffer = preg_replace('/<!--(.|s)*?-->/', '', $buffer);
    return $buffer;
function buffer_start() {
function buffer_end() {
add_action('get_header', 'buffer_start');
add_action('wp_footer', 'buffer_end');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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