Removing CPT slug from URL results in 404 error for archive page

I have created a CPT with rewrite rules as follows: “rewrite” => array( “slug” => “https://wordpress.stackexchange.com/”, “with_front” => false ), In the functions.php, I have added the following code: function sh_parse_request_tricksy( $query ) { // Only noop the main query if ( ! $query->is_main_query() ) return; // Only noop our very specific rewrite rule match … Read more

Add parent template name to body class filter when visiting subpage or single post

how would I go about creating a filter for the body_class() tag that allows me to add the the parent pages slug name as a class to the body whenever visiting a subpage or post? 3 Answers 3 here: add_filter(‘body_class’,’body_class_slugs’); function body_class_slugs($classes) { global $posts,$post; if(is_single() || is_page()){ //only on a single post or page … Read more

Is using %postname% for permalinks really that bad for performance?

I’ve seen in various places, including the WordPress admin and on this page, that using string based identifiers is “strongly not recommended for performance reasons”. I understand that looking up a string in the database is slower than looking up an integer, but in my experience it’s never a huge difference, assuming the slug field … Read more

Custom Permalink with Dynamic Taxonomy for Custom Post Type – Works, but breaks other permalinks

My custom permalink with dynamic taxonomy is working for my custom post type. However, it breaks all my other permalinks. They display a 404 error in the content area (header and sidebar still display). I used the following code to create the dynamic permalinks for the custom post type: /*Adds Custom Permalinks for Course Segments*/ … Read more

Getting author page slug from get_users() or get_userdata() functions

wp_list_authors() gives a list of author pages permalinks (site.com/author/john, site.com/author/jenny, etc). I want the same links using get_users() or get_userdata() functions instead. I need these functions because I display authors in a very customized way. However I don’t know how to get proper author page slugs with those functions. (for example, one author has an … Read more

Exclude category by slug for for each loop

I am trying to exclude some categories from a for-loop. <?php $categories = get_categories(array(‘exclude’ => ‘apps, windows’)); ?> <?php foreach ($categories as $category) : ?> // the_loop <?php endforeach; ?> Even though no error is thrown, it doesn’t work: all categories are used in the loop. How can I exclude some categories by slug? I … Read more

Remove Taxonomy Slug when No Taxonomy is Assigned to Custom Post Type?

I have a custom post type called ‘sets’ and a taxonomy set up under it called ‘project’. Most of the posts under this custom post type will be assigned one project term, but not necessarily. When a project term has not been assigned, I end up with a URL such as: example.com/sets/no-project/the-post-name In this case, … Read more

Using Blog Parent Slug on Blog Posts Only

(Advanced warning: novice question) I’m trying to find a way to add a blog slug to any blogs I post. Example: mysite.com/theblog/aparticualrblogpost mysite.com/theblog/anotherblogpost Any page created that isn’t a blog should use the standard structure: mysite.com/agenericpage mysite.com/parentpage/anothergenericchildpage How can this be achieved? 1 Answer 1 Just set your custom permalink structure to: /theblog/%postname%/ If you … Read more