If i try to add multiple classes into the the_post_pagination array class string with a space between the words it will stick them together when the code is executed. Is there a way to do this correctly?
<?php the_posts_pagination( array( 'mid_size' => 3, 'screen_reader_text' => ' ', 'next_text' => '<i class="fas fa-arrow-right"></i>' , 'prev_text' => '<i class="fas fa-arrow-left"></i>' , 'class' => 'pagination justify-content-center', ) ); ?>
Advertisement
Answer
By default, WordPress sanitizes the class that is included in a pagination, removing certain characters, space included. You can make a hack to overwrite it.
in functions.php, add the following line:
add_filter('sanitize_html_class', 'customOverwriteClass', 3, 20); function customOverwriteClass($sanitized, $class, $fallback) { if ( $class === 'your classes'){ return htmlspecialchars( $class ); } return $sanitized; }
That way, you will retain the string you need and also clean the input from malicious content. Of course change ‘your classes’ to the classes you put in the the_post_pagination function.