Viewing 7 reply threads
  • Author
    Posts
    • #5537
      bubdev
      Member

      Hi,

      I’m trying to replace the default quotes in WordPress (” “) with their german equivalents („ “). Adding a filter to the_content and doing a str_replace works fine for normal post and page content but of course not for custom fields.

      I found a solution using output buffering to do a string replace on everything before a page is sent to to browser. Again it works fine everywhere but my Piklist fields.

      ob_start();
      
      add_action('shutdown', function() {
          
          $final = '';
      
          $levels = ob_get_level();
      
          for ($i = 0; $i < $levels; $i++)
          {
              $final .= ob_get_clean();
          }
      
          // Apply any filters to the final output
          echo apply_filters('final_output', $final);
      
      }, 0);
      
      add_filter('final_output', function($text) {
      
        $text = str_replace( '“' , '„' , $text );
        $text = str_replace( '”' , '“' , $text );
        $text = str_replace( '‘' , '‚' , $text );
        $text = str_replace( '’' , '‘' , $text );
        return $text;
      
      });

      I’ve already tried different hooks to no avail. Can you think of another simple solution that would work with Piklist’s custom field content without having to deal with it on a field by field basis?

      Thank you
      Stefan

    • #5538
      bubdev
      Member

      It looks like the output buffering solution does work with normal text (“Bar” replaces “Foo”) even for Piklist fields. Only the html entities, that I have to use for my quotes problem, are being ignored.

    • #5543
      Steve
      Keymaster

      @bubdev– I’m not 100% sure I understand the issue, but I may have another solution.

      Try using a language file to change the quotes. If you create a MO file with the translation it should work everywhere. As is probably easier to implement.

    • #5549
      bubdev
      Member

      Thank you, Steve, and sorry for not making quite clear, what I’m trying to achieve. I don’t want to replace any quotation marks within my files, so the translation file won’t help. I’m aiming at the text the user types into the text editor.

      In the code I posted above the Unicode entities for the quote marks have been translated to symbols on saving the post. The str_replace part should actually look as follows (without the spaces after the ampersands):

      `add_filter( ‘final_output’, function( $text ) {

      $text = str_replace( ‘& #8220;’ , ‘& #8222;’ , $text );
      $text = str_replace( ‘& #8221;’ , ‘& #8220;’ , $text );
      $text = str_replace( ‘& #8216;’ , ‘& #8218;’ , $text );
      $text = str_replace( ‘& #8217;’ , ‘& #8216;’ , $text );
      return $text;

      });`

      The filter works fine everywhere on my site and replaces the quotation marks – except for the content of my Piklist text editor fields. They do accept a str_replace of normal text, only the Unicode entities are being ignored.

    • #5557
      Steve
      Keymaster

      Which version of Piklist are you using?

    • #5559
      bubdev
      Member

      0.9.9.6

    • #5566
      Steve
      Keymaster

      @bubdev– Can you email your plugin to [email protected] ? It will be easier for us to debug if we can see the full code.

    • #5571
      bubdev
      Member

      I’ve sent you an email. Thanks!

Viewing 7 reply threads
  • You must be logged in to reply to this topic.