Bài viết này thực hiện (hoặc lụm bài về đăng câu like từ các trang khác) bởi Việt Lâm Coder một YOUTUBER có tâm và đẹp trai siêu cấp vô địch zũ trụ. Các bạn đi ngang nếu được cho Lâm 1 like và 1 đăng ký kênh Youtube nhé !!
- Rebuild the title for all the variants used in the original
get_the_archive_title()
function:
12345678910111213141516171819202122232425262728293031323334353637383940414243<span class="com">// Return an alternate title, without prefix, for every type used in the get_the_archive_title().</span><span class="pln">add_filter</span><span class="pun">(</span><span class="str">'get_the_archive_title'</span><span class="pun">,</span> <span class="kwd">function</span> <span class="pun">(</span><span class="pln">$title</span><span class="pun">)</span> <span class="pun">{</span><span class="kwd">if</span> <span class="pun">(</span><span class="pln"> is_category</span><span class="pun">()</span> <span class="pun">)</span> <span class="pun">{</span><span class="pln">$title </span><span class="pun">=</span><span class="pln"> single_cat_title</span><span class="pun">(</span> <span class="str">''</span><span class="pun">,</span> <span class="kwd">false</span> <span class="pun">);</span><span class="pun">}</span><span class="pln"> elseif </span><span class="pun">(</span><span class="pln"> is_tag</span><span class="pun">()</span> <span class="pun">)</span> <span class="pun">{</span><span class="pln">$title </span><span class="pun">=</span><span class="pln"> single_tag_title</span><span class="pun">(</span> <span class="str">''</span><span class="pun">,</span> <span class="kwd">false</span> <span class="pun">);</span><span class="pun">}</span><span class="pln"> elseif </span><span class="pun">(</span><span class="pln"> is_author</span><span class="pun">()</span> <span class="pun">)</span> <span class="pun">{</span><span class="pln">$title </span><span class="pun">=</span> <span class="str">'<span class="vcard">'</span> <span class="pun">.</span><span class="pln"> get_the_author</span><span class="pun">()</span> <span class="pun">.</span> <span class="str">'</span>'</span><span class="pun">;</span><span class="pun">}</span><span class="pln"> elseif </span><span class="pun">(</span><span class="pln"> is_year</span><span class="pun">()</span> <span class="pun">)</span> <span class="pun">{</span><span class="pln">$title </span><span class="pun">=</span><span class="pln"> get_the_date</span><span class="pun">(</span><span class="pln"> _x</span><span class="pun">(</span> <span class="str">'Y'</span><span class="pun">,</span> <span class="str">'yearly archives date format'</span> <span class="pun">)</span> <span class="pun">);</span><span class="pun">}</span><span class="pln"> elseif </span><span class="pun">(</span><span class="pln"> is_month</span><span class="pun">()</span> <span class="pun">)</span> <span class="pun">{</span><span class="pln">$title </span><span class="pun">=</span><span class="pln"> get_the_date</span><span class="pun">(</span><span class="pln"> _x</span><span class="pun">(</span> <span class="str">'F Y'</span><span class="pun">,</span> <span class="str">'monthly archives date format'</span> <span class="pun">)</span> <span class="pun">);</span><span class="pun">}</span><span class="pln"> elseif </span><span class="pun">(</span><span class="pln"> is_day</span><span class="pun">()</span> <span class="pun">)</span> <span class="pun">{</span><span class="pln">$title </span><span class="pun">=</span><span class="pln"> get_the_date</span><span class="pun">(</span><span class="pln"> _x</span><span class="pun">(</span> <span class="str">'F j, Y'</span><span class="pun">,</span> <span class="str">'daily archives date format'</span> <span class="pun">)</span> <span class="pun">);</span><span class="pun">}</span><span class="pln"> elseif </span><span class="pun">(</span><span class="pln"> is_tax</span><span class="pun">(</span> <span class="str">'post_format'</span> <span class="pun">)</span> <span class="pun">)</span> <span class="pun">{</span><span class="kwd">if</span> <span class="pun">(</span><span class="pln"> is_tax</span><span class="pun">(</span> <span class="str">'post_format'</span><span class="pun">,</span> <span class="str">'post-format-aside'</span> <span class="pun">)</span> <span class="pun">)</span> <span class="pun">{</span><span class="pln">$title </span><span class="pun">=</span><span class="pln"> _x</span><span class="pun">(</span> <span class="str">'Asides'</span><span class="pun">,</span> <span class="str">'post format archive title'</span> <span class="pun">);</span><span class="pun">}</span><span class="pln"> elseif </span><span class="pun">(</span><span class="pln"> is_tax</span><span class="pun">(</span> <span class="str">'post_format'</span><span class="pun">,</span> <span class="str">'post-format-gallery'</span> <span class="pun">)</span> <span class="pun">)</span> <span class="pun">{</span><span class="pln">$title </span><span class="pun">=</span><span class="pln"> _x</span><span class="pun">(</span> <span class="str">'Galleries'</span><span class="pun">,</span> <span class="str">'post format archive title'</span> <span class="pun">);</span><span class="pun">}</span><span class="pln"> elseif </span><span class="pun">(</span><span class="pln"> is_tax</span><span class="pun">(</span> <span class="str">'post_format'</span><span class="pun">,</span> <span class="str">'post-format-image'</span> <span class="pun">)</span> <span class="pun">)</span> <span class="pun">{</span><span class="pln">$title </span><span class="pun">=</span><span class="pln"> _x</span><span class="pun">(</span> <span class="str">'Images'</span><span class="pun">,</span> <span class="str">'post format archive title'</span> <span class="pun">);</span><span class="pun">}</span><span class="pln"> elseif </span><span class="pun">(</span><span class="pln"> is_tax</span><span class="pun">(</span> <span class="str">'post_format'</span><span class="pun">,</span> <span class="str">'post-format-video'</span> <span class="pun">)</span> <span class="pun">)</span> <span class="pun">{</span><span class="pln">$title </span><span class="pun">=</span><span class="pln"> _x</span><span class="pun">(</span> <span class="str">'Videos'</span><span class="pun">,</span> <span class="str">'post format archive title'</span> <span class="pun">);</span><span class="pun">}</span><span class="pln"> elseif </span><span class="pun">(</span><span class="pln"> is_tax</span><span class="pun">(</span> <span class="str">'post_format'</span><span class="pun">,</span> <span class="str">'post-format-quote'</span> <span class="pun">)</span> <span class="pun">)</span> <span class="pun">{</span><span class="pln">$title </span><span class="pun">=</span><span class="pln"> _x</span><span class="pun">(</span> <span class="str">'Quotes'</span><span class="pun">,</span> <span class="str">'post format archive title'</span> <span class="pun">);</span><span class="pun">}</span><span class="pln"> elseif </span><span class="pun">(</span><span class="pln"> is_tax</span><span class="pun">(</span> <span class="str">'post_format'</span><span class="pun">,</span> <span class="str">'post-format-link'</span> <span class="pun">)</span> <span class="pun">)</span> <span class="pun">{</span><span class="pln">$title </span><span class="pun">=</span><span class="pln"> _x</span><span class="pun">(</span> <span class="str">'Links'</span><span class="pun">,</span> <span class="str">'post format archive title'</span> <span class="pun">);</span><span class="pun">}</span><span class="pln"> elseif </span><span class="pun">(</span><span class="pln"> is_tax</span><span class="pun">(</span> <span class="str">'post_format'</span><span class="pun">,</span> <span class="str">'post-format-status'</span> <span class="pun">)</span> <span class="pun">)</span> <span class="pun">{</span><span class="pln">$title </span><span class="pun">=</span><span class="pln"> _x</span><span class="pun">(</span> <span class="str">'Statuses'</span><span class="pun">,</span> <span class="str">'post format archive title'</span> <span class="pun">);</span><span class="pun">}</span><span class="pln"> elseif </span><span class="pun">(</span><span class="pln"> is_tax</span><span class="pun">(</span> <span class="str">'post_format'</span><span class="pun">,</span> <span class="str">'post-format-audio'</span> <span class="pun">)</span> <span class="pun">)</span> <span class="pun">{</span><span class="pln">$title </span><span class="pun">=</span><span class="pln"> _x</span><span class="pun">(</span> <span class="str">'Audio'</span><span class="pun">,</span> <span class="str">'post format archive title'</span> <span class="pun">);</span><span class="pun">}</span><span class="pln"> elseif </span><span class="pun">(</span><span class="pln"> is_tax</span><span class="pun">(</span> <span class="str">'post_format'</span><span class="pun">,</span> <span class="str">'post-format-chat'</span> <span class="pun">)</span> <span class="pun">)</span> <span class="pun">{</span><span class="pln">$title </span><span class="pun">=</span><span class="pln"> _x</span><span class="pun">(</span> <span class="str">'Chats'</span><span class="pun">,</span> <span class="str">'post format archive title'</span> <span class="pun">);</span><span class="pun">}</span><span class="pun">}</span><span class="pln"> elseif </span><span class="pun">(</span><span class="pln"> is_post_type_archive</span><span class="pun">()</span> <span class="pun">)</span> <span class="pun">{</span><span class="pln">$title </span><span class="pun">=</span><span class="pln"> post_type_archive_title</span><span class="pun">(</span> <span class="str">''</span><span class="pun">,</span> <span class="kwd">false</span> <span class="pun">);</span><span class="pun">}</span><span class="pln"> elseif </span><span class="pun">(</span><span class="pln"> is_tax</span><span class="pun">()</span> <span class="pun">)</span> <span class="pun">{</span><span class="pln">$title </span><span class="pun">=</span><span class="pln"> single_term_title</span><span class="pun">(</span> <span class="str">''</span><span class="pun">,</span> <span class="kwd">false</span> <span class="pun">);</span><span class="pun">}</span> <span class="kwd">else</span> <span class="pun">{</span><span class="pln">$title </span><span class="pun">=</span><span class="pln"> __</span><span class="pun">(</span> <span class="str">'Archives'</span> <span class="pun">);</span><span class="pun">}</span><span class="kwd">return</span><span class="pln"> $title</span><span class="pun">;</span><span class="pun">});</span> - Or, simply strip anything that looks like a title prefix (which may alter actual titles which contain a word followed by the colon character):
1234<span class="com">// Simply remove anything that looks like an archive title prefix ("Archive:", "Foo:", "Bar:").</span><span class="pln">add_filter</span><span class="pun">(</span><span class="str">'get_the_archive_title'</span><span class="pun">,</span> <span class="kwd">function</span> <span class="pun">(</span><span class="pln">$title</span><span class="pun">)</span> <span class="pun">{</span><span class="kwd">return</span><span class="pln"> preg_replace</span><span class="pun">(</span><span class="str">'/^\w+: /'</span><span class="pun">,</span> <span class="str">''</span><span class="pun">,</span><span class="pln"> $title</span><span class="pun">);</span><span class="pun">});</span>
Bài viết này thực hiện (hoặc lụm bài về đăng câu like từ các trang khác) bởi Việt Lâm Coder một YOUTUBER có tâm và đẹp trai siêu cấp vô địch zũ trụ. Các bạn đi ngang nếu được cho Lâm 1 like và 1 đăng ký kênh Youtube nhé !!