This page short URL: 6u

Rendering cleanup

As we have seen before, Accelerated Mobile Pages only accepts a subset of what regular HTML pages can display. Most notably, forms, javascript and external CSS is not accepted, which will prevent some of your plugins to do their job properly. weeblrAMP already has some features to let you control this, and will "sanitize" your pages when converting them from standard HTML to AMP.

But sometimes this is not enough, as plugins can leave some shortcodes, or other artifacts in your content. They are not removed automatically by weeblrAMP, simply because they are valid AMP content, but they simply may not look good.

Under the Cleanup tab of weeblrAMP configuration, you will find options to let you remove undesired content:

weeblrAMP advanced settings: CSS-based cleanup

CSS-based cleanup

weeblrAMP can remove from AMP pages any HTML element that has CSS class(es) or a CSS id(s) in a specified list. Enter one or more CSS classes or ids in the corresponding input field, one per line. If an HTML element has one of the classes, group of classes or ids on that list, it will be automatically removed from any AMP page.

To remove an element that has at the same time 2 or more classes, list those classes on the same line. The order does not matter: as long as an element has all classes showing on a line, it will be removed. With a setup such as the one from the screenshot above:

  • any element with the class wbamp-remove-on-amp will be removed
  • any element with the class some-class will be removed
  • any element which has both the pull-left and item-image classes will be removed
  • the element with id item-fruits-category will be removed

If you cannot modify the CSS classes/id of an element you want to remove, you can just list CSS classes or id it already has. Beware that maybe other elements have the same classes, so you may cause multiple elements to be removed. You may need to adjust the list until you get the desired output. Ids are simpler has there should (theoretically) only be one element per page with a given id. However, in practice, fewer elements have ids.

Instead of listing many CSS classes to be removed, it is usually faster to just add the wbamp-remove-on-amp class wherever you need. It is the default value for this input field

Cleanup expressions

cleanup expressions are regular expressions used to search and replace content on AMP pages. They are more geared toward programmers, which can use them to select pretty much any content they want

This feature is only supported in the regular edition of weeblrAMP.

How to use the setting

To add a cleanup expression

Each expressions lives on a separate line, and follows this format:

full_php_regular_expression => "replacement_text"

The regular expression in the first part of the line will be run before the page is displayed (using PHP preg_replace), and the text it matches will be replaced by the text replacement_text, which must be between double-quotes.

To remove some content, just make the replacement_text equals to "".

Here is an example:

#\[slider[^\]]*\]#iuUs  => "<br />"

This cleanup expression will cause the text [slider] to be replaced with <br />, each time it is found in a page content.

To disable one line

Enter a ; as the first character of this line. This can be used to add some information about your cleanup expression, for easier management.

To disable entirely this feature

Simply enter a - as the first line of the input field (you do not need to delete the rest of the field).