WordPress CPT slug and page slug conflicts

As you don’t need the CPT archvie, the easiest way to use example.com/new-site to open a page, and example.com/new-site/post-slug to open single posts of “new-site” post type, is to declare has_archive => false when registering the CPT: add_action( ‘init’, ‘cyb_register_cpt’ ); function cyb_register_cpt() { $args = array( // ….. ‘has_archive’ => false ); register_post_type( ‘new-site’, … Read more

Remove some rewrite rules in wordpress

You can modify the global WP_Rewrite variable directly. add_action(‘init’, function(){ global $wp_rewrite; echo “<pre>”; var_dump($wp_rewrite); wp_die(); }); There are sevel properties you can adjust: $wp_rewrite->permalink_structure $wp_rewrite->use_trailing_slashes $wp_rewrite->author_base $wp_rewrite->search_base $wp_rewrite->comments_base $wp_rewrite->pagination_base $wp_rewrite->comments_pagination_base $wp_rewrite->feed_base $wp_rewrite->front $wp_rewrite->root $wp_rewrite->index $wp_rewrite->matches $wp_rewrite->rules $wp_rewrite->extra_rules $wp_rewrite->extra_rules_top $wp_rewrite->non_wp_rules $wp_rewrite->extra_permastructs $wp_rewrite->endpoints $wp_rewrite->use_verbose_rules $wp_rewrite->use_verbose_page_rules $wp_rewrite->rewritecode $wp_rewrite->rewritereplace $wp_rewrite->queryreplace $wp_rewrite->feeds And alternate removal functions: $wp_rewrite->remove_permastruct $wp_rewrite->remove_rewrite_tag

website with pretty permalinks except pagination

WP permalink handling is sort of layered. They underlying “ugly” permalinks capture the actual logic of the system and the “pretty” permalinks are just cosmetic enhancement on top of it. Even when pretty permalinks are enabled, the original ugly permalinks still continue to work. But under normal circumstances they get redirected to a pretty version. … Read more

show ALL latest posts with archive.php on example.com/latest

All internal rules must point to index.php. This isn’t your theme’s index.php file, this is the main core WordPress bootstrap file. Rewrite rules set query vars, query vars get parsed into queries, those queries have template files associated with them depending on type. Internal rewrite rules never point directly to theme files. If you want … Read more

Rewrite without query parameter

The wordpress “rewrite rules” have a horrible name which do not match what people are expecting it to be. Those are not rules to rewrite or redirect or whatever other things you can do with htaccess, but rules which are used to “rewrite” urls into the relevant WP_Query parameters. Therefor if you have a rewrite … Read more

Custom Rewrite Rule for Custom Post Type with URL Param

SOLUTION: I am answering my own question here since no responses were given and I presume this might be helpful to someone and in the mean while I found a solution.. I had to use the second version of ‘add_rewrite_rule’: add_rewrite_rule( ‘^products/directory/?([^/]*)/?’, ‘index.php?post_type=acme_product&c=$matches[1]’, ‘top’ ); I needed to register a query var,, since external query … Read more

Is it possible to register a new template file?

I would strongly suggest you use a WordPress page template. At the top of dashboard.php: <?php /** * Template Name: Dashboard */ Now create a page called “Dashboard” and assign it the dashboard template. This way you’re not loading WordPress yourself (nearly always bad) & WordPress & all your plugins will function as normal (creating … Read more