Clicky

  1. Home
  2. Developer Docs
  3. Extending
  4. How to Override Blacklist Sanitizer?
  1. Home
  2. Developer Docs
  3. How to Override Blacklist Sanitizer?

How to Override Blacklist Sanitizer?

Let’s override the blacklist sanitizer to allow forms in AMP.

First Create a new plugin say AMP Custom Plugin (You can check this tutorial if you don’t know how to do it: Custom Plugin for AMP )

Create a new file for the class in the AMP Custom Plugin folder you have just created say “class-amp-blacklist”

In“class-amp-blacklist” include the blacklist sanitizer class and write a new class to extend AMP_Blacklist_Sanitizer.

Here is the code to achieve this task:
AMP New Blacklist Sanitizer

When you go down in the code you will see a function called get_blacklisted_tags, this is the function which is stripping the tags like form. As you can see I have commented the elements which will make the form to work in AMP.

Call this file in the main file of AMP Custom Plugin

Unset the AMP_Blacklist_Sanitizer and add Set our new class for the sanitization.

After doing these steps, forms will not be stripped from the AMP Content.

But there might still be an error of action in AMP, so there are two options for this, use custom AMP Editor and change action to action-xhr or filter the content and replace the action with action-xhr.

You can filter the content like this:

You can style the forms with either custom CSS or with the hook;

This is how you can do it with the hook:

Now you can add forms in AMP without any worries.

You can read more about AMP forms here: Forms in AMP

If you find any issues in this or have any queries, feel free to comment or reach out to us. 🙂

Ask your Questions Directly!
If you can't find the solutions in this article, then just ask us in the comments and we will answer it for you!
Updated on April 5, 2018

Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help!
Contact Support

Leave a Comment