Replace content in WordPress output

Last Updated: January 28, 2019

add_action( 'init', 'turn_on_output_buffering', 10, 0 );
add_action( 'wp_footer', 'ob_end_flush', 10, 0 );
function turn_on_output_buffering() {
	ob_start( 'change_text' );
}
function change_text( $buffer ) {
	$search_for = "text1";
	$replace_with ="text2";
	return str_replace( $search_for, $replace_with, $buffer );
}

Add your feedback or comment below: