Skip to content

Instantly share code, notes, and snippets.

@tanftw
Last active August 29, 2015 14:22
Show Gist options
  • Save tanftw/a4284f0d057c4f72182b to your computer and use it in GitHub Desktop.
Save tanftw/a4284f0d057c4f72182b to your computer and use it in GitHub Desktop.
Snake case in WP
<?php
/**
* Convert a regular string to snake_case
* For example, Hello World => hello_world
*
* @param String $str String to be converted
* @return String String in snake_case
**/
function str_snake( $str )
{
return str_replace( '-', '_', sanitize_title( $str ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment