Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Random string in permastructure
- * Use %random% in "Permastructure" settings
- */
- function pm_random_string_field($default_uri, $native_slug, $post, $slug, $native_uri) {
- // Do not affect native URIs
- if($native_uri == true || empty($post->post_type)) { return $default_uri; }
- if(strpos($default_uri, '%random%') !== false) {
- $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $length = 12;
- $random_string = substr(str_shuffle($chars), 0, $length);
- $default_uri = str_replace('%random%', $random_string, $default_uri);
- }
- return $default_uri;
- }
- add_filter('permalink_manager_filter_default_post_uri', 'pm_random_string_field', 3, 5);
Add Comment
Please, Sign In to add comment