Change custom taxonomy archive permalink

You can use the rewrite parameter to customize the taxonomy permalinks. Here’s an example which links the taxonomy to the default post post type: register_taxonomy( ‘video_category’, ‘post’, [ ‘public’ => true, ‘rewrite’ => [ ‘slug’ => ‘videos/category’, ], // … your other parameters .. ] ); Don’t forget to flush the rewrite rules — just … Read more

How to add a sub directory to WordPress single posts without affecting other post types?

If we look at the register_post_type documentation, in the rewrite option, there is a sub-option that controls this: ‘with_front’ => bool Should the permalink structure be prepended with the front base. (example: if your permalink structure is /blog/, then your links will be: false->/news/, true->/blog/news/). Defaults to true So something like this: … ‘rewrite’ => … Read more

Different options per post type in WP_Query

You could use pre_get_posts to conditionally add the tax_query depending on post-type, here’s a simple example. <?php function wpse_377928( $the_query ){ $post_type = $the_query->get(‘post_type’); if ( ‘type_a’ === $post_type ) { $tax_query = [ [ ‘taxonomy’ => ‘tax-1’, ‘field’ => ‘term_id’, ‘terms’ => array(11, 12, 13), ] ]; } elseif ( ‘type_b’ === $post_type ) … Read more

why post_class() function apply css classes to all other files?

where to use the post_class() You can use it pretty much everywhere (in WordPress), e.g. single post pages (single.php, single-my_cpt.php, etc.), search results pages (search.php), the index template (index.php), a template part (e.g. content.php), and a shortcode function. it is ok to use post_class() for adding custom classes? Yes, it is. post_class() is not restricted … Read more