Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $rewrite = [
- 'slug' => 'single-link',
- 'with_front' => false,
- 'pages' => false,
- 'feeds' => false,
- ];
- $args = [
- 'label' => esc_html__( 'Single Link', 'single-link' ),
- 'labels' => $labels,
- 'supports' => [ 'title' ],
- 'hierarchical' => false,
- 'public' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'menu_position' => 15,
- 'menu_icon' => 'dashicons-admin-links',
- 'show_in_admin_bar' => false,
- 'show_in_nav_menus' => true,
- 'can_export' => true,
- 'has_archive' => false,
- 'exclude_from_search' => true,
- 'publicly_queryable' => true,
- 'rewrite' => $rewrite,
- 'capability_type' => 'page',
- 'show_in_rest' => true,
- ];
- $args = apply_filters( 'single-link/post_type/args', $args );
- register_post_type( 'single-link', $args );
- function remove_cpt_slug( $post_link, $post, $leavename ) {
- if ( 'single-link' != $post->post_type || 'publish' != $post->post_status ) {
- return $post_link;
- }
- $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
- return $post_link;
- }
- add_filter( 'post_type_link', 'remove_cpt_slug', 10, 3 );
- function change_slug_struct( $query ) {
- if ( ! $query->is_main_query() || 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) {
- return;
- }
- if ( ! empty( $query->query['name'] ) ) {
- $query->set( 'post_type', array( 'post', 'single-link', 'page' ) );
- }
- }
- add_action( 'pre_get_posts', 'change_slug_struct' );
Add Comment
Please, Sign In to add comment