Untitled
unknown
plain_text
a year ago
838 B
5
Indexable
// Function to change the permalink structure for posts
function custom_post_type_permalinks($post_link, $post) {
if ( 'post' == get_post_type( $post ) ) {
// Replace 'journal' with your desired prefix
return home_url( '/journal/' . $post->post_name . '/' );
}
return $post_link;
}
add_filter( 'post_type_link', 'custom_post_type_permalinks', 10, 2 );
// Function to add rewrite rules for posts
function custom_rewrite_rules() {
add_rewrite_rule(
'^journal/([^/]+)/?$',
'index.php?name=$matches[1]',
'top'
);
}
add_action('init', 'custom_rewrite_rules');
// Ensure WordPress flushes rewrite rules on theme switch
function custom_flush_rewrite_rules() {
custom_rewrite_rules();
flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'custom_flush_rewrite_rules' );
Editor is loading...
Leave a Comment