Wordpress SEO - What are you looking for?

If you're looking for answers to SEO or wordpress related questions, type in a phrase and wait for hints or click enter! The results also show links to external sources.

161 articles in the database

WordPress spam protection without plugins

[ Article content is protected by Plagiashield ]


Spam is probably the worst thing, after hacking, that people face users WordPress. At the moment there are many different ways to protect pagesI don't want to be a spammer. But most of them involve installing additional plugs. If you are not a fan of this approach to solving the problem (the fact that each additional plug increases the loading time websites), we propose a simple solution. Just enter a few changes to file functions themeto forget about the advertising comments added via various spam scripts.

The solution given is that we hide the real comment entry field 'comment' and replace it with a new field 'real-comment'. For blog visitors everything will remain the same and they will not notice any difference on website. However, spam scripts will try to populate a standard comment field with a standard name 'comment'. The problem is that the script will not be able to understand that the proposed field is invisible to visitors. As a result, filling it in causes that the person filling it in is recognized as an "automat" and takes him to the page with a notification "Stop spam".

Therefore To make the appropriate changes, modify the file functions.php theme used by default. We will therefore use the standard editor WordPresswhich can be found in section Appearance. Use this editor to open the theme functions file (Figure 1):

Figure 1. modification of functions.php file

We will insert the following code at the end of this file:

//add a 'real-comment' field start
function wph_add_new_comment_field($args) {
    if (preg_match('//', $args['comment_field'], $match)){
        $textarea = $match[0];
        $real_textarea = str_replace('comment', 'real-comment', $textarea, $count);
        if ($count) {
            $hidden_textarea = str_replace( '

With this code, there will be 2 identical fields for entering comments with different names on the add comments page. At the same time the standard field 'comment' is hidden before through the eyes of the visitors and they can't fill it in any way.

Now we will add the code that will check whether is filled in 'comment'. If so, the message will be marked as spam and a new message will open website with a "Stop spam" message:

//check for spam
function wph_verify_spam() {
    if(false === strpos($_SERVER['REQUEST_URI'], 'wp-comments-post.php'))
        wp_die('Stop spam');
    $_POST['comment'] = $_POST['real-comment'];
add_filter('init', 'wph_verify_spam');

After saving all changes, we go to the entry page (Figure 2).

Figure 1. modification of functions.php file

Like can be seen from Figure 2 for user nothing has changed. Form Comments have the same fields as before. After filling them in, the comment will await moderation (fig. 3). If you have different settings in section Discussionhe may already be added.

Figure 3: Expectations of comments for moderation

Therefore, in order to check that the changes you made are working correctly, you need to enter the following field  '