admin管理员组

文章数量:1315829

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 1
Add a comment  | 

2 Answers 2

Reset to default 0

Not 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)

本文标签: pluginsReplace only the first CSS class