I'm trying to replace the "thumb-w" CSS class with "thumb-w1", just the first time. This is the starting function:
function start_modify_html() {
ob_start();
}
function end_modify_html() {
$html = ob_get_clean();
$html = str_replace( 'thumb-w', 'thumb-w 1', $html);
echo $html;
}
add_action( 'wp_head', 'start_modify_html' );
add_action( 'wp_footer', 'end_modify_html' );
I tried entering "1" in the str_replace in this way:
$html = str_replace( 'thumb-w', 'thumb-w 1', $html);
but it doesn't seem to work. Can you help me? Thanks
I'm trying to replace the "thumb-w" CSS class with "thumb-w1", just the first time. This is the starting function:
function start_modify_html() {
ob_start();
}
function end_modify_html() {
$html = ob_get_clean();
$html = str_replace( 'thumb-w', 'thumb-w 1', $html);
echo $html;
}
add_action( 'wp_head', 'start_modify_html' );
add_action( 'wp_footer', 'end_modify_html' );
I tried entering "1" in the str_replace in this way:
$html = str_replace( 'thumb-w', 'thumb-w 1', $html);
but it doesn't seem to work. Can you help me? Thanks
Share Improve this question asked Nov 17, 2020 at 21:34 marcorromamarcorroma 12 Answers
Reset to default 0Not sure if a typo but in your question you say "replace the "thumb-w" CSS class with "thumb-w1"
but in your code you have: $html = str_replace( 'thumb-w', 'thumb-w 1', $html);
Should your code instead remove the space and be: str_replace( 'thumb-w', 'thumb-w1', $html);
I solved it with thi code:
$html = preg_replace('/thumb-w/', 'thumb-w nolazyload', $html, 1)