0

I try to add each letter, entity, special character from post title to array but quote symbols not working. I use this function in the loop and single post page.

Entities are in the numeric HTML format and I must convert all entities to their character counterparts by using wp_kses_decode_entities function.

Quote symbols like ' or " not work.

Title: Test ‘, *, -, +, `, ~, @, #, $, %, ^, *, (, ), _, &, <, >, “, and ‘.

Function:

if ( !function_exists( 'animated_title' ) ):
    function animated_title( $str = '', $max_chars = 100 ) {
        $output = '';

        add_filter( 'run_wptexturize', '__return_false' );
        $str = empty( $str ) ? get_the_title() : $str;
        $str = wp_specialchars_decode( $str, ENT_QUOTES );
        $str = wp_kses_normalize_entities( $str );
        $str = wp_kses_decode_entities( $str );
        add_filter( 'run_wptexturize', '__return_true' );

        if ( empty( $str ) ) {
            return $output;
        }

        return print_r( str_split ( $str ) );

    }
endif;

Custom string:

animated_title('Test ‘, *, -, +, `, ~, @, #, $, %, ^, *, (, ), _, &, <, >, “, and ‘');

Output:

Array
(
    [0] => T
    [1] => e
    [2] => s
    [3] => t
    [4] =>  
    [5] => �
    [6] => �
    [7] => �
    [8] => ,
    [9] =>  
    [10] => *
    [11] => ,
    [12] =>  
    [13] => -
    [14] => ,
    [15] =>  
    [16] => +
    [17] => ,
    [18] =>  
    [19] => `
    [20] => ,
    [21] =>  
    [22] => ~
    [23] => ,
    [24] =>  
    [25] => @
    [26] => ,
    [27] =>  
    [28] => #
    [29] => ,
    [30] =>  
    [31] => $
    [32] => ,
    [33] =>  
    [34] => %
    [35] => ,
    [36] =>  
    [37] => ^
    [38] => ,
    [39] =>  
    [40] => *
    [41] => ,
    [42] =>  
    [43] => (
    [44] => ,
    [45] =>  
    [46] => )
    [47] => ,
    [48] =>  
    [49] => _
    [50] => ,
    [51] =>  
    [52] => &
    [53] => a
    [54] => m
    [55] => p
    [56] => ;
    [57] => ,
    [58] =>  
    [59] => <
    [60] => ,
    [61] =>  
    [62] => >
    [63] => ,
    [64] =>  
    [65] => �
    [66] => �
    [67] => �
    [68] => ,
    [69] =>  
    [70] => a
    [71] => n
    [72] => d
    [73] =>  
    [74] => �
    [75] => �
    [76] => �
)

Post title:

animated_title();

Output:

Array
(
    [0] => T
    [1] => e
    [2] => s
    [3] => t
    [4] =>  
    [5] => 
    [6] => ,
    [7] =>  
    [8] => *
    [9] => ,
    [10] =>  
    [11] => -
    [12] => ,
    [13] =>  
    [14] => +
    [15] => ,
    [16] =>  
    [17] => `
    [18] => ,
    [19] =>  
    [20] => ~
    [21] => ,
    [22] =>  
    [23] => @
    [24] => ,
    [25] =>  
    [26] => #
    [27] => ,
    [28] =>  
    [29] => $
    [30] => ,
    [31] =>  
    [32] => %
    [33] => ,
    [34] =>  
    [35] => ^
    [36] => ,
    [37] =>  
    [38] => *
    [39] => ,
    [40] =>  
    [41] => (
    [42] => ,
    [43] =>  
    [44] => )
    [45] => ,
    [46] =>  
    [47] => _
    [48] => ,
    [49] =>  
    [50] => &
    [51] => a
    [52] => m
    [53] => p
    [54] => ;
    [55] => ,
    [56] =>  
    [57] => <
    [58] => ,
    [59] =>  
    [60] => >
    [61] => ,
    [62] =>  
    [63] => 
    [64] => ,
    [65] =>  
    [66] => a
    [67] => n
    [68] => d
    [69] =>  
    [70] => �
    [71] => �
    [72] => �
)
  • 1
    I don't really understand what it is you want to achieve and where you're currently failing. Could you elaborate (via edit in the question), what your input and what the actual & desired output is? – kero Oct 8 '18 at 11:39
  • 1
    @kero Updated question and decription. Thanks for your time. – Michael Oct 8 '18 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.