I need to escape/translate text that also requires HTML within in the copy. Use printf()
<h3><?php printf( esc_html__( 'Get our exclusive newsletter—the best of %1$s The Dude %2$s every day!', 'localdude' ), '<span>', '</span>' ); ?></h3>
I need to replace different parts of text in a string with new text. Example below replaces text in a embedded YouTube video src
. Also uses explode
and array_keys
<?php
$return = '<iframe src="#"></iframe>>'; // example iframe code
$id = explode( 'watch?v=', $url );
$replace_keys = array(
'allowfullscreen>' => 'allowfullscreen id="yt-' . $id[1] . '">',
'?feature=oembed' => '?enablejsapi=1',
);
$html = str_replace( array_keys( $replace_keys ), $replace_keys, $return );
return $html;
?>