I want to have a custom permalink for each new post in WordPress like: http://mysite.com/x5Kvy6 (like bit.ly).
I tried this little script, but it adds only 5-digit numbers to the post title in the permalink.
function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) {
if($slug!=""){
$random=rand(11111,99999); //I needed 5 digit random
$slug .= "-" . $random;
}
return $slug;
}
How can I make a random key instead of the post title?
I have not researched URL shorteners or redirection methods.
Any idea is welcome!
.= is for concat of strings.
The correct way to use Mwayi answer is using the filter
wp_unique_post_slug
, asfunction wp_unique_post_slug()
will conflit with WP own function. Inside WP function we find this filter hook.This can be optimised in a number of ways.
Also regarding this
wp_unique_post_slug()
-- yikes watch out for the name spacing. Wordpress already uses this function nameFor SEO, you better keep the slug as meaningful as possible, ie. do not change the permalink to a random sequence. Using This plugin, you still can use http://example.com/raNd0m permalink for sharing purposes in social networks or images from your site.
This way you win both SEO and shortlinks
I used http://ijassar.info/underrated to write a post about this specific subject