{"id":10710,"date":"2021-04-20T10:07:02","date_gmt":"2021-04-20T10:07:02","guid":{"rendered":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/dplugins.com\/?post_type=code_snippets&#038;p=10710"},"modified":"2026-10-10T19:53:26","modified_gmt":"2026-10-10T19:53:26","slug":"remove-archive-prefix","status":"publish","type":"post","link":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/remove-archive-prefix\/","title":{"rendered":"Remove the Archive Title Prefix in WordPress"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">WordPress archive titles start with a prefix: &#8220;Category: News&#8221;, &#8220;Tag: Recipes&#8221;, &#8220;Archives: Products&#8221;, &#8220;Author: Jane&#8221;. Most designs only want the name.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This one-line snippet removes the prefix from every WordPress archive title, in classic themes and in block themes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The snippet<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php\n\/**\n * Remove the \"Category:\", \"Tag:\", \"Archives:\" and similar prefixes from WordPress archive titles.\n *\/\nadd_filter( 'get_the_archive_title_prefix', '__return_empty_string' );<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Add it with Scripts Organizer<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/dplugins.com\/downloads\/scripts-organizer\/\">Scripts Organizer<\/a> go to <strong>Code Blocks \u2192 Add New<\/strong> and give the block a name. Set <strong>Trigger location<\/strong> to <strong>Everywhere<\/strong>, tick <strong>PHP<\/strong> under <strong>Script location<\/strong>, paste the code into the PHP editor and publish. Leave <strong>Action\/Hook<\/strong> empty. The filter only runs when a template asks for the archive title.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The same code also works unchanged in a small plugin or an mu-plugin.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How it works<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>get_the_archive_title()<\/code> builds the title from a prefix and the name. Since WordPress 5.5 the prefix has its own filter, <code>get_the_archive_title_prefix<\/code>.<\/li>\n\n\n<li>Returning an empty string from that filter makes WordPress return the plain name, without the <code>&lt;span&gt;<\/code> it normally wraps around it.<\/li>\n\n\n<li>It works for every archive type: categories, tags, custom taxonomies, authors, dates and post type archives, in every language.<\/li>\n\n\n<li>The earlier version split the title at <code>: <\/code>, which failed in languages that use other punctuation and depended on a <code>screen-reader-text<\/code> class. Its header also had a copied description about Oxygen fonts.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Variant: keep the prefix for screen readers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you want the prefix hidden visually but still read out by screen readers, use this instead. It needs the <code>screen-reader-text<\/code> class, which most themes define.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php\n\/**\n * Hide the prefix visually but keep it for screen readers.\n * Needs the .screen-reader-text class, which most themes define.\n *\/\nadd_filter( 'get_the_archive_title_prefix', 'dpc_archive_title_prefix_screen_reader' );\n\nfunction dpc_archive_title_prefix_screen_reader( $prefix ) {\n\treturn '' === $prefix ? $prefix : '&lt;span class=\"screen-reader-text\"&gt;' . esc_html( $prefix ) . '&lt;\/span&gt;';\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Gotchas<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In block themes the <strong>Query Title<\/strong> block has a <strong>Show archive type in title<\/strong> toggle; you can switch it off per template without code. The snippet does the same for every template at once.<\/li>\n\n\n<li>Themes that print their own heading (for example <code>single_cat_title()<\/code>) never had a prefix; this filter does not change them.<\/li>\n\n\n<li>Only one archive type? See <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/remove-category-text-in-archive-page-title\/\">Remove \u201cCategory:\u201d text in archive page title<\/a>.<\/li>\n\n<\/ul>\n\n","protected":false},"excerpt":{"rendered":"<p>Remove &#8220;Category:&#8221;, &#8220;Tag:&#8221;, &#8220;Archives:&#8221; and the other prefixes from WordPress archive titles with one filter, in classic and block themes.<\/p>\n","protected":false},"author":9,"featured_media":46707,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Remove the Archive Title Prefix in WordPress - Code DPlugins","description":"Remove \"Category:\", \"Tag:\", \"Archives:\" and the other prefixes from WordPress archive titles with one filter, in classic and block themes."},"_slim_seo_primary_term_category":0,"_slim_seo_primary_term_post_tag":0,"footnotes":""},"categories":[3],"tags":[],"dpc_library":[204],"class_list":["post-10710","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress"],"_links":{"self":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/10710","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/comments?post=10710"}],"version-history":[{"count":1,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/10710\/revisions"}],"predecessor-version":[{"id":46706,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/10710\/revisions\/46706"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media\/46707"}],"wp:attachment":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media?parent=10710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/categories?post=10710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/tags?post=10710"},{"taxonomy":"dpc_library","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/dpc_library?post=10710"}],"curies":[{"name":"wp","href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/api.w.org\/{rel}","templated":true}]}}