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