How to add a custom URL placeholder to author archives?

Option 1 I assume custom post type generate a URL something like this domain.com/%custom-post-type%/%list% So you could write it so it looks as… since the main URL doesn’t have author before custom type you would have to do this via a function since authors are dynamic RewriteRule ^members/%author%/(.*)$ domain.com/%custom-post-type%/$1 This doesn’t specifically modify the custom … Read more

Removing hierarchical pages in the permalink

I’d be curious if someone can find a better solution to this. Here’s what I came up with: function wpse_91821_flatten_page_paths( $wp ) { if ( false !== strpos( $wp->matched_query, ‘pagename=” ) && isset( $wp->query_vars[“pagename’] ) && $wp->query_vars[‘pagename’] && false === strpos( $wp->query_vars[‘pagename’], “https://wordpress.stackexchange.com/” ) ) { if ( !get_page_by_path( $wp->query_vars[‘pagename’] ) ) { $page = … Read more

Regex in add_rewrite_tag not accepting OR operators?

I don’t know what’s wrong but I can suggest: Use Rewrite Rules Inspector or similar to see where your %psubject% rule is and if its pattern ((option1|option2|option3)) has been added correctly. Test http://example.com/somecategory/option1/this-is-the-post-title with the Inspector to see which rule matches. Open http://example.com/somecategory/option1/this-is-the-post-title (when it shows home.php) with the Debug Bar plugin and look at … Read more

WordPress Custom Post Type is Matching on Partial Slug

Add this code in your active theme’s functions.php file and it should stop WordPress guessing the source of the incomplete slug: function no_redirect_guess_404_permalink( $header ){ global $wp_query; if( is_404() ) unset( $wp_query->query_vars[‘name’] ); return $header; } add_filter( ‘status_header’, ‘no_redirect_guess_404_permalink’ ); Original answer here

Taxonomy term in permalink

Take a look at this post How to create a permalink structure with custom taxonomies and custom post types like base-name/parent-tax/child-tax/custom-post-type-name Accompanied by: How to change permalink structure for custom post type and it’s taxonomies? and Custom post types, taxonomies, and permalinks It will cover what you are trying to do for /category/subcategory/othersubcategory/posttitle. Edit: I … Read more

Archive permalinks

The really easy way: Change your permalink structure to include a “front” part. Eg. /news/%postname% The slightly more complicated and inflexible way: WordPress holds it’s data permastruct in a property of the global WP_Rewrite object stored in $wp_rewrite. You can hook in sometime early-ish (around init) and change this. <?php add_action(‘init’, ‘wpse39274_change_date’); function wpse39274_change_date() { … Read more

Date based URLs for custom posts and pagination

Calling $GLOBALS[“wp_rewrite”]->flush_rules() did make everything work as I required but that wouldn’t be a good solution. Actually, you have to flush the rewrite rules after modifying them (i.e. also when registering custom post types). Also, you should never rely on these global variables. WordPress provides specific functions for nearly everything. For example, use flush_rewrite_rules() instead … Read more