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 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)
本文标签: pluginsReplace only the first CSS class
版权声明:本文标题:plugins - Replace only the first CSS class 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741985706a2408662.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论