How to modify HTML output in WordPress using Filters

How to modify HTML output in WordPress using Filters, you can use functions ob_start and ob_end_flush functions to accomplish this.

 

Use following code.

<?php

function callback($buffer) {

$buffer = str_replace(array(“src=”, “srcset=”), array(“src=\”http://localhost/wordpress_tutorials/wp-content/uploads/2017/12/aqua-wind-breaker-2-free-img-300×300.jpg\” data-src=”, “somethingelse=”), $buffer);

return $buffer;
}

function buffer_start() {
ob_start(“callback”);
}

function buffer_end() {
ob_end_flush();
}

add_action(‘wp_head’, ‘buffer_start’);
add_action(‘wp_footer’, ‘buffer_end’);

?>

 

Please watch this video to understand more.

Leave a Comment