Last active
December 18, 2015 23:19
-
-
Save AlexPashley/5861087 to your computer and use it in GitHub Desktop.
PHP: Dynamic slug function with SEO improvements
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
<?php | |
/** | |
* Used to give the full hyperlink for dynamic items | |
* | |
* @param $type string - events/news | |
* @param $id int - ID of item for link | |
* @param $title string - item title for link to strip bad chars | |
**/ | |
function seo_slug ( $type, $id, $title ) | |
{ | |
// strip bad chars | |
$slug = trim(strtolower(preg_replace("/[^a-zA-Z0-9\s]/", "", $title))); | |
$slug = str_replace(' ','-', $slug); | |
$slug = str_replace(' ','-', $slug); | |
return '/'.$type.'/'.$id.'/'.$slug.'/'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment