WordPress Growth Stack Trade is a query and reply web site for WordPress builders and directors. It solely takes a minute to enroll.
Anyone can ask a query
Anyone can reply
The very best solutions are voted up and rise to the highest
Requested
Considered
6 instances
As an example I wish to write a plugin that replaces (i.e.: overwrites) each src
-tag of each iframe-element on a WP-Web site with a customized string AND the plugin shall watch each new submit or page-edit at any time when a brand new iframe is inserted, how would I’m going about it? Is there one thing like an event-api for WP each time an edit seen on the frontend happens?
-
Use the “save_post” motion hook, which is triggered each time a submit or web page is created or up to date. Within the perform referred to as by the hook, you may examine the submit content material for brand new iframes, and if discovered, exchange the src attributes of iframe parts earlier than they’re saved to the database.
-
Use the “the_content” filter hook, which lets you modify the submit content material earlier than it’s displayed on the frontend. Within the perform referred to as by the filter, you may exchange the src attributes of all iframe parts on the web site with a customized string.
-
To restrict the plugin performance to sure submit varieties, you may examine the submit sort earlier than making the alternative in each the “save_post” and “the_content” capabilities.
-
As soon as the plugin is prepared, activate it within the WordPress backend and it’ll begin listening for submit and pages adjustments and changing the iframe src attributes as per your customized string.
default