Last active
August 29, 2015 13:57
-
-
Save klihelp/9529141 to your computer and use it in GitHub Desktop.
WordPress - Prefix Custom Post Type posts slugs
This file contains hidden or 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 | |
/** | |
* Prefix Posts Slugs | |
* This hooks into wp_unique_post_slug and adds prefix to post slug. Eg: have post Hello title and slug will be my-prefix-hello. | |
* @author Klipolis | |
* @since 0.1.0 | |
* @version 0.1.0 | |
* @access public | |
* @main WordPress | |
*/ | |
/** | |
* Prefix my post slugs | |
*/ | |
add_filter( 'wp_unique_post_slug', 'prefix_wp_unique_post_slug', 2, 6 ); | |
function prefix_wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) { | |
if ( $post_type, 'my_postype_only') ) { | |
$prefix = 'my-prefix-'; | |
if ( strripos($slug, $prefix) !== 0 ) { | |
$slug = $prefix . $slug; | |
} | |
} | |
return $slug; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment