Add below code into functions.php file
function change_slug_struct( $query ) {
if ( is_single() ) {
// If you want pass all custom post types array dynamically then use below code
$get_cpt_args = array('public' => true, '_builtin' => false);
$post_types = get_post_types( $get_cpt_args, 'object' );
// do something with array
$post_type_array = array();
if ( $post_types ) {
foreach ( $post_types as $cpt_key => $cpt_val ) {
array_push($post_type_array, $cpt_key);
}
}
//That's it
if ( ! $query->is_main_query() || 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) {
return;
}
if ( ! empty( $query->query['name'] ) ) {
// Option 1 - specific CPT passed here
$query->set( 'post_type', array( 'custom_post_type1, 'custom_post_type2', 'single-link', 'page' ) );
// Option 2 - all CPT passed here dynamically
$query->set( 'post_type', array( $post_type_array ) );
} elseif ( ! empty( $query->query['pagename'] ) && false === strpos( $query->query['pagename'], '/' ) ) {
// Option 1 - specific CPT passed here
$query->set( 'post_type', array( 'custom_post_type1, 'custom_post_type2', 'single-link', 'page' ) );
// Option 2 - all CPT passed here dynamically
$query->set( 'post_type', array( $post_type_array ) );
// We also need to set the name query var since redirect_guess_404_permalink() relies on it.
$query->set( 'name', $query->query['pagename'] );
}
}
}
add_action( 'pre_get_posts', 'change_slug_struct' );
Your ideas absolutely shows this site could easily be one of the bests in its niche. Drop by my website QU6 for some fresh takes about Cosmetics. Also, I look forward to your new updates.