Skip to main content
Share Your Experience: Take the 2024 Developer Survey
22 votes

Remove "Category:", "Tag:", "Author:" from the_archive_title

For CPT title Without word: ‘Archive’: If you are building custom archive template for a CPT, and want to output just the title of the CPT with no extra word like “Archive” use following function ...
Mike Castro Demaria's user avatar
22 votes
Accepted

Why are posts from custom post type not displayed in "category" archive?

You need to hook into the query because the category archive page explicitly only includes the 'post' type and nothing else. function namespace_add_custom_types( $query ) { if( (is_category() || ...
socki03's user avatar
  • 1,932
16 votes

Get list of years when posts have been published

Your question is pretty old, but I just wanted to add a real solution to your question. Here's a function that will return an array of years you have posts published in. You can put this function in ...
Gavin's user avatar
  • 384
13 votes

Remove "Category:", "Tag:", "Author:" from the_archive_title

as of Wordpress 5.5 you can remove the prefix with this hook: add_filter('get_the_archive_title_prefix','__return_false');
Andrew J Klimek's user avatar
11 votes

Remove "Category:", "Tag:", "Author:" from the_archive_title

I feel like this is over simplifying things, but this is what I did... <h1><?php echo str_replace("Archives: ", "", get_the_archive_title()); ?></h1>
Tisch's user avatar
  • 219
10 votes

How to get the custom post type from an archive page?

Here is the function you want: /** * Get the current archive post type name (e.g: post, page, product). * * @return String|Boolean The archive post type name or false if not in an archive page. *...
Nabil Kadimi's user avatar
  • 2,686
10 votes
Accepted

How to remove "Archive:" label from archive title

You need to use the filter get_the_archive_title. It works like the_title filter. More details about the function that embed the filter here More in this question remove category tag EDIT : When ...
Benoti's user avatar
  • 2,436
9 votes
Accepted

Add custom field to the archive page?

Using the Advanced Custom Fields plugin you can assign options pages to you custom posttype like this: if( function_exists('acf_add_options_page') ) { acf_add_options_page(array( '...
Luckyfella's user avatar
8 votes
Accepted

Check if current term is a child of another term

There are two problems that have thwarted your check: $term = get_queried_object()->term_id; if ( $term->parent == 'tradeshow' ) { Starting with: $term = get_queried_object()->...
Tom J Nowell's user avatar
  • 59.5k
7 votes

Display posts on a custom page from only a specific category?

Get First Five Posts With Specific Category <?php // the query $the_query = new WP_Query(array( 'category_name' => 'post_category_name', 'post_status' =&...
Muhammad Bilal's user avatar
7 votes
Accepted

$query->set in pre_get_posts is unintentionally affecting the backend

In regards to your decision not to use WP_Query, pre_get_posts is actually an excellent choice to make, rather than creating a new instance of WP_Query. In fact, pre_get_posts is exactly what you ...
Tim Malone's user avatar
  • 4,754
7 votes

How to remove "Archive:" label from archive title

Also, you can remove unnecessary words from any standard title: add_filter( 'get_the_archive_title', function ($title) { if ( is_category() ) { $title = single_cat_title( '', false ); } elseif ...
Sergey  Fedirko's user avatar
7 votes

Adding active/current class to get_terms list

Run a conditional check in the foreach loop using is_category($term-name) Assign a class variable to active if it's the same as $term->name $terms = get_terms( 'category' ); echo '<ul>'; ...
Ian's user avatar
  • 969
7 votes
Accepted

Display custom post type taxonomies as an archive page

Your desired URLs: www.example.com/results/post-name/ www.example.com/results/categories/category-name/ Two changes from your original code: Priority was added to both add_action hooks to reverse ...
Milo's user avatar
  • 78.5k
7 votes
Accepted

Modify query in pre_get_posts action is messing up my nav menu

pre_get_posts runs for every query. That includes the main query, secondary queries, and menus. The problem is that is_post_type_archive(array('provider')) is checking if the main query is the post ...
Jacob Peattie's user avatar
7 votes

Display "add to cart" button on every listing in product category page?

You can use the WooCommerce hook woocommerce_after_add_to_cart_button. This hook will add content after the "Add To Cart" button. If the customer clicks on this button, the product should ...
Mohammad Arif's user avatar
6 votes

Get custom post type slug for an archive page

The answers get confusing. And maybe Im as well but the headline question is: Get custom post type slug for an archive page If you mean post type archive landing-page, and when ...
cavameta's user avatar
  • 183
6 votes

Check if current term is a child of another term

All these answers are so overpowered and extremely long. I've just used this in 2 lines of code: $term = get_queried_object(); $is_parent = $term->parent == 0 ? true : false; Essentially, this is ...
Jake's user avatar
  • 69
6 votes
Accepted

Use is_product_category() properly

is_product_category() is to be used on woocommerce category archive pages only so first make sure that you are on category archive. instead of category number use category slug name ...
Shamsur Rahman's user avatar
6 votes
Accepted

How to hide custom taxonomy archives same way as hiding custom post types?

If you set public to false, this taxonomy will get hidden in all places. So if you want it to be visible in wp-admin, you’ll have to also set show_ui to true - it will show the admin interface to ...
Krzysiek Dróżdż's user avatar
5 votes

How to get the custom post type from an archive page?

I see this in a few comments on the accepted answer, but wanted to make this point clear for others skimming over these answers: The global $wp_query object is more reliable for getting the archive's ...
James's user avatar
  • 208
5 votes
Accepted

Archive for a Taxonomy of a Custom Post type

If I am understanding you have a taxonomy that is shared across multiple post types? And you want to make a custom template for each post type using the Wordpress's templating system. Which isn't ...
ngearing's user avatar
  • 2,144
5 votes

Custom Post Type Archive URL takes over page URL

When you register your post type, set the has_archive argument to false. If you change it, don't forget to flush your rewrite rules to see the change. Now this works fine if, as you asked, you want ...
Andy Macaulay-Brook's user avatar
5 votes

Custom Post Type Archive template page not found

I don't think you need to use the hook pre_get_posts on this. Remove that part from functions.php. Then just put the archive-technology.php in themes root directory. Then go to you Permalinks settings ...
CodeMascot's user avatar
  • 4,527
5 votes
Accepted

Archive page with multiple taxonomies rewrite

ok, so I thought I'd come back and answer my own question in case its useful to someone else. To start, the CPT: 'query_var' => true, 'has_archive' => false, 'rewrite' => array( ...
jedifunk's user avatar
  • 101
4 votes

Force Wordpress to Show Pages Instead of Category

I created the following, fairly simple function in order to make the pages a higher importance than categories when loading the content. (Note: this may not the best, but a simple way. I found an ...
bencergazda's user avatar
4 votes

When 'is_post_type_archive()' return true?

When 'is_post_type_archive()' return true? is_post_type_archive() returns true for custom post type archives and false for default posts. Use is_archive() to check for default posts.
bravokeyl's user avatar
  • 3,369
3 votes

Get list of years when posts have been published

You could use this function to get all the post years in a array, which you could use to loop with. $terms_year = array( 'post_type' => array('YOUR_CPT'), ); $years = array(); $...
Lou Jonker's user avatar
3 votes

Force Wordpress to Show Pages Instead of Category

There is a super simple and perfectly working answer here: https://stackoverflow.com/questions/32310453/make-wordpress-use-the-page-instead-of-category For the sack of completeness: Background ...
Paul Woods's user avatar
3 votes

Remove "Category:", "Tag:", "Author:" from the_archive_title

echo '<h1 class="page-title">' . single_cat_title( '', false ) . '</h1>'; in taxonomy-category.php outside public of theme.
Hoang Oanh's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible