Skip to content

Instantly share code, notes, and snippets.

@omniacode
Last active October 22, 2020 15:14
Show Gist options
  • Save omniacode/ff0eff76ea759c6695a0d50578a24890 to your computer and use it in GitHub Desktop.
Save omniacode/ff0eff76ea759c6695a0d50578a24890 to your computer and use it in GitHub Desktop.
Modify Registered Custom Post Types Args
/**
* Filter the Products CPT to register more options.
*
* @param $args array The original CPT args.
* @param $post_type string The CPT slug.
*
* @return array
*/
function custom_permalink_mod( $args, $post_type ) {
// If not CPT, bail.
if ( 'registered-post-type' !== $post_type ) {
return $args;
}
// Add additional CPT options.
$custom_args = array(
'rewrite' => array(
'slug' => 'post-type-slug',
'with_front' => false,
)
);
// Merge args together.
return array_merge( $args, $custom_args );
}
add_filter( 'register_post_type_args', 'custom_permalink_mod', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment