Advertisement
Guenni007

change_quotes

Jun 5th, 2023 (edited)
843
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. function change_quotation_marks() {
  5.  
  6.   // Content
  7.   add_filter( 'the_content' , 'alternative_quotes', 12 );
  8.   add_filter( 'the_excerpt', 'alternative_quotes', 12 );
  9.   add_filter( 'comment_text', 'alternative_quotes', 12 );
  10.   add_filter( 'widget_text', 'alternative_quotes', 12 );
  11.  
  12.  
  13.   function alternative_quotes( $text ) {
  14.     $use_str_replace = false;
  15.     if ( strpos( get_locale(), 'de_' ) === 0 ) {
  16.       $text = wptexturize( $text );
  17.     }
  18.     else {
  19.       return $text;
  20.     }
  21.  
  22.     if (
  23.         ( strpos( $text, '&#8222;' ) !== false && strpos( $text, '&#171;' ) === false ) ||
  24.         ( strpos( $text, '&#8220;' ) !== false && strpos( $text, '&#187;' ) === false )
  25.     ) {
  26.         $use_str_replace = true;
  27.     }
  28.  
  29.     // Replace English curly quotes
  30.     if ( $use_str_replace ) {
  31.       $text = str_replace( '&#8222;' , '&#171;' , $text ); // replace english curly double open
  32.       $text = str_replace( '&#8220;' , '&#187;' , $text ); // replace english curly double close
  33.     }
  34.     return $text;
  35.   }
  36. }
  37. add_action( 'wp', 'change_quotation_marks' );
  38.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement