Skip to content

Instantly share code, notes, and snippets.

@ryanduff ryanduff/rewrite.php
Created May 25, 2016

Embed
What would you like to do?
<?php
add_filter( 'post_type_link', 'post_type_links', 10, 4 );
/**
* Generates custom permalink structures
*
* @since 1.0.0
*
* @param string $permalink Current permalink
* @param object $post Current post object
* @param boolean $leavename
* @param string $sample
*
* @return string Generated permalink
*/
public function post_type_links( $permalink, $post, $leavename = false, $sample ) {
if ( in_array( $post->post_type, array( 'conference', 'member', 'organization' ) ) ) {
// Allow for slug to be editable
$slug = $leavename ? '%' . $post->post_type . '%' : $post->post_name;
// Generate premalink prefix based on post type
$prefix = $post->post_type;
// Array of custom permalink tabs
$permalink_tags = array(
'%prefix%',
'%postname%',
);
// Array of permalink values
$permalink_values = array(
$prefix,
$slug,
);
// Generate the permalink
$permalink = str_replace( $permalink_tags, $permalink_values, '/%prefix%/%postname%/' );
$permalink = user_trailingslashit( home_url( $permalink ) );
}
return $permalink;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.