Snippets / PHP
PHP
Generate Random 25 Character Permalink
D
Donald McGuinn
·
239 views
·
Updated 2 years ago
This REQUIRES permalink manager (free). Grab a copy here.
This snippet allows you to add the random string to the permalink instead of the default wordpress one. This is good to make each URL unique, a little bit of privacy and hard to memorize for security reasons.
This snippet allows you to add the random string to the permalink instead of the default wordpress one. This is good to make each URL unique, a little bit of privacy and hard to memorize for security reasons.
function pm_random_string_field( $default_uri, $native_slug, $post, $slug, $native_uri ) {
// Do not affect native URIs
if ( $native_uri || empty( $post->post_type ) ) {
return $default_uri;
}
if ( false !== strpos( $default_uri, '%random%' ) ) {
$length = 25;
$random_string = wp_generate_password( $length, false );
$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 );
PHP · 16 lines
Discussion
Ask a question or share how you used this.
Log in
to join the discussion.
No comments yet — be the first.