0

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).

Thanks,
Josh

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

2 Answers 2

0

You put this function there:

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

Did it work?

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

1
  • 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. Jun 6, 2017 at 18:29
0

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() {
    ob_start("callback");
}
function buffer_end() {
    ob_end_flush();
}
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.