Skip to content

Instantly share code, notes, and snippets.

@jazbek
Created September 27, 2012 16:33
Show Gist options
  • Save jazbek/3794979 to your computer and use it in GitHub Desktop.
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.
/**
* 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