Reply To: Not working with the Lore theme

Forums Forums Remove CPT base Not working with the Lore theme Reply To: Not working with the Lore theme

#282
ViorelMocanu
Participant

No, sorry. I ended up not using your plugin to solve this, but embedding some code in functions.php myself.

I can, however, share what eventually worked for me. The custom post type Lore generates is called lsvr_kba

	    // ultrahack for routing because WordPress FTW
	    register_post_type( 'lsvr_kba',
		    array(
			    'rewrite' => false
		    )
	    );
	    function custom_post_type_rewrites() {
		    add_rewrite_rule( '[^/]+/attachment/([^/]+)/?$', 'index.php?attachment=$matches[1]', 'bottom');
		    add_rewrite_rule( '[^/]+/attachment/([^/]+)/trackback/?$', 'index.php?attachment=$matches[1]&tb=1', 'bottom');
		    add_rewrite_rule( '[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?attachment=$matches[1]&feed=$matches[2]', 'bottom');
		    add_rewrite_rule( '[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?attachment=$matches[1]&feed=$matches[2]', 'bottom');
		    add_rewrite_rule( '[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$', 'index.php?attachment=$matches[1]&cpage=$matches[2]', 'bottom');
		    add_rewrite_rule( '[^/]+/attachment/([^/]+)/embed/?$', 'index.php?attachment=$matches[1]&embed=true', 'bottom');
		    add_rewrite_rule( '([^/]+)/embed/?$', 'index.php?custom_post_type=$matches[1]&embed=true', 'bottom');
		    add_rewrite_rule( '([^/]+)/trackback/?$', 'index.php?custom_post_type=$matches[1]&tb=1', 'bottom');
		    add_rewrite_rule( '([^/]+)/page/?([0-9]{1,})/?$', 'index.php?custom_post_type=$matches[1]&paged=$matches[2]', 'bottom');
		    add_rewrite_rule( '([^/]+)/comment-page-([0-9]{1,})/?$', 'index.php?custom_post_type=$matches[1]&cpage=$matches[2]', 'bottom');
		    add_rewrite_rule( '([^/]+)(?:/([0-9]+))?/?$', 'index.php?lsvr_kba=$matches[1]', 'bottom');
		    add_rewrite_rule( '[^/]+/([^/]+)/?$', 'index.php?attachment=$matches[1]', 'bottom');
		    add_rewrite_rule( '[^/]+/([^/]+)/trackback/?$', 'index.php?attachment=$matches[1]&tb=1', 'bottom');
		    add_rewrite_rule( '[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?attachment=$matches[1]&feed=$matches[2]', 'bottom');
		    add_rewrite_rule( '[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?attachment=$matches[1]&feed=$matches[2]', 'bottom');
		    add_rewrite_rule( '[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$', 'index.php?attachment=$matches[1]&cpage=$matches[2]', 'bottom');
		    add_rewrite_rule( '[^/]+/([^/]+)/embed/?$', 'index.php?attachment=$matches[1]&embed=true', 'bottom');
	    }
	    add_action( 'init', 'custom_post_type_rewrites' );
	    function custom_post_type_permalinks( $post_link, $post, $leavename ) {
		    if ( isset( $post->post_type ) && 'lsvr_kba' == $post->post_type ) {
			    $post_link = home_url( $post->post_name );
		    }
		    return $post_link;
	    }
	    add_filter( 'post_type_link', 'custom_post_type_permalinks', 10, 3 );

I also added a function to prevent duplicates since everything is on root now (categories, posts, everything) but that’s out of scope here.