Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

REGEX to remove code from posts WordPress


I'm using [[LINK href=""]]interconnect tool[[/LINK]] (search & replace script) to remove some code from a lot of WP posts.

I could manage to remove/change some content, but there is a shortcode + text code that I wasn't able to remove.

The code has the following pattern:

[toggle title="QUADRO DE VAGAS"]

some variable text...


Real example:

[toggle title="QUADRO DE VAGAS"]

Auxiliar de Administração;1;Ensino Fundamental Completo.;40 horas;1.014,94;100,00
Oficial Administrativo;CR;Ensino Médio Completo.;40 horas;2.074,01;120,00


Could you build a regular expression to identify all code from [toggle title="QUADRO DE VAGAS"] to [/toggle] (including "toggle" shortcode)?

The regex should be build in a way that I can put in in the search field of the interconnect between the "/ /" (attached image).


Answers (3)


Rempty answers:

You can use this regex
\[toggle title="QUADRO DE VAGAS"]((.+?)?\[\/toggle\])?
and check mark the s(try without checkmark too)
Apply first in a test enviorement or make a db backup

gualha comments:

Will try this. Thanks.
I can make a "dry run" for testing and also DB is backed up.


Bob answers:

You want to remove shrotcode only and keep text right?

why you want to remove/replace shortcodes? are you switching theme?

gualha comments:

Hello Bob! I need to remove shortcode [toggle title="QUADRO DE VAGAS"] including all text between shortcode opening/closing brackets.

Still the same theme for now, but this code that I'm trying to remove isn't compatible with Google AMP pages.


Reigel Gallarde answers:

you don't really need to remove this shortcode...

you can have it even when using amp pages, where it would only show on normal pages and not on amp pages..

let me know if you're interested in this kind of approach...