Guenni007 icon

change_quotes

Guenni007 | PRO | 06/05/23 05:11:10 PM UTC (Edited) | 0 ⭐ | 1328 👁️ | Never ⏰ | []
PHP |

1.07 KB

|

None

|

0 👍

/

0 👎

<?php
 
 
function change_quotation_marks() {
 
  // Content
  add_filter( 'the_content' , 'alternative_quotes', 12 );
  add_filter( 'the_excerpt', 'alternative_quotes', 12 );
  add_filter( 'comment_text', 'alternative_quotes', 12 );
  add_filter( 'widget_text', 'alternative_quotes', 12 );
 
 
  function alternative_quotes( $text ) {
    $use_str_replace = false;
    if ( strpos( get_locale(), 'de_' ) === 0 ) {
      $text = wptexturize( $text );
    }
    else {
      return $text;
    }
 
    if (
        ( strpos( $text, '&#8222;' ) !== false && strpos( $text, '&#171;' ) === false ) ||
        ( strpos( $text, '&#8220;' ) !== false && strpos( $text, '&#187;' ) === false ) 
    ) {
        $use_str_replace = true;
    }
 
    // Replace English curly quotes 
    if ( $use_str_replace ) {
      $text = str_replace( '&#8222;' , '&#171;' , $text ); // replace english curly double open
      $text = str_replace( '&#8220;' , '&#187;' , $text ); // replace english curly double close
    }
    return $text;
  }
}
add_action( 'wp', 'change_quotation_marks' );
 

Comments