Search and Replace Plugin (CMSR) - Use Case - How to Filter and Remove Inappropriate Content from Comments


Use Case - How to Filter and Remove Inappropriate Content from Comments

Back to User Guide

Note: This guide covers features from:


Introduction

The Search and Replace plugin enables you to replace text across posts, pages, and content generated by themes or plugins.

It works via rules: you tell it  "x" should become "y". Then, everytime a visitor visits a page with "x", he/she will see "y".

Note that the content will only change to the visitor. By default the change will not be applied to your database.

Use Case Front-End

Removing/replacing a spam link in the comment:

Replacing a spam link in the comment - WordPress Plugin Search and Replace
Replacing a spam link in the comment

Removing/replacing rude words in the comment:

Replacing rude words in the comment - WordPress Plugin Search Database and Replace
Replacing rude words in the comment

Use Case Assumptions

In this example use case guide, we'll consider how to remove unwanted content from comments on your site, such as spam links and rude words. You can apply the same idea for removing or replacing other types of unwanted content from comments.

We consider that you have already bought the plugin, but not installed it. 

It follows:

Installing the Plugin

The process is the same for all CM plugins.

CreativeMinds Customer Account Dashboard - Downloads tab
CreativeMinds Customer Account Dashboard
  • Download the plugin from your customer dashboard.
  • Log in to WordPress and navigate to the WordPress Admin â†’ Plugins settings.
  • Click on Add New.
  • Activate it and add the license.

Learn more: Getting Started - Plugin Overview


Quick Recap

In this use case guide, we will focus specifically on removing unwanted content from comments. If you want to learn more about the plugin and its features, you can check out the more general use case guide:

Using Regex

Regular expressions (regex) are powerful patterns used to match and manipulate specific text. By defining clear patterns, regex allows precise filtering and ensures that only the intended text is modified or removed. This makes it an essential tool for automating content moderation efficiently.

Regex is ideal for tasks like detecting and removing links or other unwanted content since it allows you to define a single pattern rather than creating separate rules for each instance. So, if you want to remove or replace links, you just use that one pattern, and it will catch all the links at once. The same idea applies to other things, like unwanted tags or bad words.

Creating Search and Replace Rules

Now let's go through the basic process of creating search and replace rules and consider a few options we will need in this use case guide.

To create search and replace rules in the Search and Replace plugin, navigate to Admin Dashboard → Search & Replace → Settings → Replacement Rules tab.

Navigation to the dashboard for managing replacement rules - Find and Replace Plugin WordPress
Navigation to the dashboard for managing replacement rules

At the top of the tab you can find the search field and two checkboxes "For" and "By". It will help you to search and navigate between multiple replacement rules that you can create.

Bar for searching the replacement rules - WordPress Plugin to Mass Replace Links
Bar for searching the replacement rules

Below the search bar there's a button Add New S&R Rule which shows or hides a form for creating rules:

Form for creating rules - Mass Replace Text in WordPress
Form for creating rules

The form by default shows only basic options. More options can be shown or hidden by clicking Expand / Collapse Additional Settings:

Expanding additional settings - WordPress Plugin Search and Replace
Expanding additional settings

The options we will need in this use case are:

Options used in current use case - WordPress Plugin Search Database and Replace
Options used in current use case
  1. Search For - Enter here the content you want to replace. That's the field where we will place our regular expressions.
  2. Replace By - Enter here the content that you want to be displayed instead of the searched content. If you leave this field empty, the content from the Search For field will not be replaced, but just removed.
  3. Regex - Enabling this option is required if you want the content placed to the Search For field to be parsed as a regex rule.
  4. Exclusions - This option allows to not apply the rule to the associated area. For our use case this option is useful as we will be able to exclude from searching and replacing all areas except the comments section.

Note

To parse content in the comments section of your site, you need to make sure that the relevant option is enabled in the plugin settings. To do that, head to the Settings tab and enable the option Post/Page Comments in case if it's not enabled yet, then save the changes.

Enabling parsing content in comments - Find and Replace Plugin WordPress
Enabling parsing content in comments

The form for creating search and replace rules has more options than we considered. If you want to learn more about all of them and how to manage all your rules, please check this user guide:

Now let's move on to creating rules for removing unwanted content.

First case we are going to consider is removing spam links.

Let's say that someone has left a comment that contains a link to the competitor site:

Comment example - WordPress Plugin to Mass Replace Links
Comment example

To avoid appearing unwanted links in comments, we will use the following regex:

  • /<a\b[^>]*>(.*?)<\/a>/

This rule detects all content wrapped with the <a> tag which displays a link.

So let's create a rule. We configure the rule in the following way:

Example of the search and replace rule - Mass Replace Text in WordPress
Example of the search and replace rule
  • Search For - We add here our regular expression.
  • Replace By - We type here text that will be displayed instead of the link.
  • Regex - Enable this option.
  • Exclusions - Here we exclude all items except Links and Comments.

Then click the button Add Rule.

Now let's see the result on the front-end - the link is replaced by text we defined:

Replacement example - WordPress Plugin Search and Replace
Replacement example

Removing Rude Words

Second case we are going to consider is removing rude words.

For example, we have some users that leave comments with lots of rude words:

Comment example - WordPress Plugin Search Database and Replace
Comment example

To avoid such kind of language in comments, we will use the following regex:

  • \b(word1|word2|word3)\b

This regex allows to detect multiple specific words.

So let's create a rule. We configure the rule in the following way:

Example of the search and replace rule - Find and Replace Plugin WordPress
Example of the search and replace rule
  • Search For - Using regex we define words which we want to remove or replace.
  • Replace By - We type here text that will be displayed instead of the found word.
  • Regex - Enable this option.
  • Exclusions - Here we exclude all items except Comments.

Then click the button Add Rule.

Now let's see the result on the front-end - the all specified rude words are replaced by another content:

Replacement example - WordPress Plugin to Mass Replace Links
Replacement example

End Result

Following instructions found in the Search and Replace plugin and guides, you should be able to remove unwanted content from comments on your site, such as spam links and rude words.

Use Case Front-End

Removing/replacing a spam link in the comment:

Replacing a spam link in the comment - Mass Replace Text in WordPress
Replacing a spam link in the comment

Removing/replacing rude words in the comment:

Replacing rude words in the comment - Search and Replace Plugin
Replacing rude words in the comment

More information about the Search and Replace Plugin for WordPress

Other WordPress products can be found at CreativeMinds WordPress Store

Let us know how we can Improve this Product Documentation Page

To open a Support Ticket visit our support center
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.