Last active
November 16, 2022 15:04
-
-
Save 19h47/cde74dede05ad9ea9b9e4904d8ef19c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: WP Sanitize Title With Underscores | |
* Plugin URI: https://gist.github.com/19h47/c54fd0e7a5c6fbc99a6087e7606054c0 | |
* Description: Simple wrapper around sanitize_title_with_dashes to replacing dashes with underscores. | |
* Version: 0.0.1 | |
* Author: Jérémy Levron | |
* Author URI: https://19h47.fr | |
* | |
* @package 19h47/wp-sanitize-title-with-underscore | |
*/ | |
if ( ! function_exists( 'sanitize_title_with_underscores' ) && function_exists( 'sanitize_title_with_dashes' ) ) { | |
/** | |
* Sanitize a title, replacing dashes by underscores. | |
* | |
* @param string $title The title to be sanitized. | |
* @param string $raw_title (Optional) Not used. Default value: ''. | |
* @param string $context (Optional) The operation for which the string is sanitized. When set to 'save', additional entities are converted to hyphens or stripped entirely. Default value: 'display'. | |
* | |
* @see https://developer.wordpress.org/reference/functions/sanitize_title_with_dashes/ | |
* | |
* @return string The sanitized title. | |
*/ | |
function sanitize_title_with_underscores( string $title, string $raw_title = '', string $context = 'display' ) : string { | |
return str_replace( '-', '_', sanitize_title_with_dashes( $title, $raw_title, $context ) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment