Sanitizes a html classname to ensure it only contains valid characters.
Strips the string down to A-Z,a-z,0-9,_,-. If this results in an empty string, then the function will return the alternative value supplied. After sanitize_html_class()
has done its work, it passes the sanitized class name through the sanitize_html_class filter.
<?php // If you want to explicitly style a post, you can use the sanitized version of the post title as a class $post_class = sanitize_html_class( $post->post_title ); echo '<div class="' . $post_class . '">';
sanitize_html_class()
is located in wp-includes/formatting.php
.
sanitize_html_class()
is in a class of functions that help you sanitize potentially unsafe data which allow you to pass an arbitrary variable and receive the clean version based on data type. Others include: