Created
September 27, 2012 16:33
-
-
Save jazbek/3794979 to your computer and use it in GitHub Desktop.
Function to strip articles from slug. Slug can then be used to alphabetize post listings.
This file contains 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
/** | |
* strip_articles_from_slug | |
* | |
* Remove a, an, the from post slugs on new posts, so post listings | |
* can be alphabetized by slug and ignore leading articles | |
* | |
* @param $postarr post being set up | |
* @param $data data for the database | |
* @return array | |
* @author Jessica Yazbek | |
**/ | |
function strip_articles_from_slug($data, $postarr) | |
{ | |
if ( ! $postarr['post_name']) // new post without slug specified | |
{ | |
$data['post_name'] = str_replace(array('~~~the-', '~~~a-', '~~~an-', '~~~'), array('', '', '', ''), '~~~'.$data['post_name']); | |
} | |
return $data; | |
} | |
add_filter('wp_insert_post_data', 'strip_articles_from_slug', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment