Rewrite Page with a slug before page name

I’ve not tried external rules, but you can achieve that with an internal rewrite and pagename: function wpd_page_rewrite(){ add_rewrite_rule( ‘^anothername/([^/]*)/?’, ‘index.php?pagename=$matches[1]’, ‘top’ ); } add_action( ‘init’, ‘wpd_page_rewrite’ ); For parent/child pages you have to set pagename to the parent/child path, page/pagename, or you can also use page_id and use the page’s ID. EDIT – note … Read more

expecting 404 but redirecting to post with url subdirectory in post title

The magic you’re referring to happens in redirect_canonical(). And more specifically, redirect_guess_404_permalink(). You can cut in ahead of redirect_canonical by hooking onto the template_redirect action with a slightly higher priority – in this case, anything lower than 10. function wpse_145210_redirect_canonical() { if ( is_404() && $name = get_query_var( ‘name’ ) ) { // The following … Read more

template_include not loading -instead goes to index.php

in order for the discography rule to work, I changed the rule from: add_rewrite_rule( ‘artists/([^/]+)/discography/?$’, ‘index.php?album_artist=$matches[1]&discography=yes’, ‘top’); to this : add_rewrite_rule( ‘artists/([^/]+)/discography/?$’, ‘index.php?artists=$matches[1]&discography=yes’, ‘top’); What the original rule was doing was pointing to the Artist’s Name and not the Artists custom post type, thus failing to redirect to the template. Thanks a lot to @RachelCarden … Read more

how to get archive urls with same origin for custom types and terms?

So, a first solution can be using add_rewrite_rules(). A first raw logic should be something like: 1- get term slugs you need, save in a var, say $terms_string; $terms_string should be a list of pipe-separeted slugs, suitable for regexp, like ‘type1|type2’ etc.. containing ONLY valid (allowed) values. Say use get_terms() to get all the slugs.. … Read more

Load a template page based on part of slug in wordpress

You can filter template_include, check the request URL for your search words and return a custom template. Here is a primitive example: add_filter( ‘template_include’, function( $template ) { $template_map = [ ‘advice-on’ => ‘advice’, ‘links-‘ => ‘link-collection’, ]; foreach ( $template_map as $find => $match ) { if ( 0 === strpos( $_SERVER[ ‘REQUEST_URI’ ], … Read more

Rewrite Custom Post Type URL slug

If the city and region is always city and region strings, you can do something like this. For your specific case, you could do it like this: ‘rewrite’ => array( ‘slug’ => ‘city/region/event’ ), ‘hierarchical’ => true, ‘has_archive’ => false, ‘supports’ => array( ‘title’, ‘editor’, ‘thumbnail’, ‘page-attributes’), If the city becomes some city and the … Read more

Is it possible to remove feeds from rewrites?

Why are you removing rewrite rules? These should not noticeably impact performance, unless there were thousands of entries. Yes, you can remove them, but you will break any functionality associated with those urls, and you won’t improve your site’s speed at all. If you’re concerned about site speed, check out YSlow and Google Page Speed … Read more