Skip to content

Instantly share code, notes, and snippets.

@sareiodata
Created October 17, 2018 13:46
Show Gist options
  • Save sareiodata/0457992ed986da8fcd4bd933ff90908e to your computer and use it in GitHub Desktop.
Save sareiodata/0457992ed986da8fcd4bd933ff90908e to your computer and use it in GitHub Desktop.
add_filter('trp_before_translate_content', 'trpc_fix_html_attributes_without_spaces');
function trpc_fix_html_attributes_without_spaces($output){
$size = strlen($output);
$pos = 0;
$pos_c = 0;
while ($pos_c < $size){
$len = strcspn($output, '<' , $pos);
$pos += $len;
$len_c = strcspn($output, '>' , $pos);
$pos_c += $len_c;
$even_detection_apostrophe = 0;
$even_detection_quote = 0;
for ($i = $pos; $i < $pos_c; $i++){
$char = $output[$i]; //next
if ($char == '"' ){
$even_detection_quote ++;
if ( $even_detection_quote % 2 == 0){
$output = substr_replace( $output, ' ', $i+1, 0 );
}
}
if ($char == "'" ){
$even_detection_apostrophe ++;
if ( $even_detection_apostrophe % 2 == 0){
$output = substr_replace( $output, ' ', $i+1, 0 );
}
}
}
$pos_c ++;
$pos = $pos_c;
}
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment