Skip to content

Instantly share code, notes, and snippets.

@dantetesta
Created May 30, 2023 15:59
Show Gist options
  • Save dantetesta/443bd5c65fd656874774aef5c55f1b38 to your computer and use it in GitHub Desktop.
Save dantetesta/443bd5c65fd656874774aef5c55f1b38 to your computer and use it in GitHub Desktop.
function custom_produtos_rewrite_rule() {
add_rewrite_rule(
'^([^/]+)/?$',
'index.php?post_type=produtos&name=$matches[1]',
'top'
);
}
add_action('init', 'custom_produtos_rewrite_rule', 10, 0);
function custom_post_type_link( $post_link, $post ) {
if ( 'produtos' === $post->post_type && 'publish' === $post->post_status ) {
return home_url( "/" . $post->post_name );
}
return $post_link;
}
add_filter( 'post_type_link', 'custom_post_type_link', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment