KODE UNTUK KESELURUHAN JUDUL PADA HOME, KATEGORI, TAG
====================================================
function titleLimitChar($title){
if(strlen($title) > 30 && !(is_single()) && !(is_page())){ // not in single post page and page.
$title = substr($title,0,30) . "..";
}
return $title;
}
add_filter( 'the_title', 'titleLimitChar' );
KODE HANYA UNTUK KATEGORI TERTENTU (SATU, DUA, ATAU LEBIH KATEGORI)
============================
function titleLimitChar($title){
if(is_category( '9' )){
if(strlen($title) > 30 && !(is_single()) && !(is_page())){ // not in single post page and page.
$title = substr($title,0,30) . "..";
}
return $title;
}else{
return $title;
}
}
add_filter( 'the_title', 'titleLimitChar' );
PENJELASAN:
in the is_category() you use category id, category name and catgory-slug etc.
For Multiple categories just pass array in the parameter as
array( 9, 'blue-cheese', 'Stinky Cheeses' )
Other uses to check specific category or categories as below from the WordPress developer portal.
is_category();
// When any Category archive page is being displayed.
is_category( '9' );
// When the archive page for Category 9 is being displayed.
is_category( 'Stinky Cheeses' );
// When the archive page for the Category with Name "Stinky Cheeses" is being displayed.
is_category( 'blue-cheese' );
// When the archive page for the Category with Category Slug "blue-cheese" is being displayed.
is_category( array( 9, 'blue-cheese', 'Stinky Cheeses' ) );
SUMBER: https://stackoverflow.com/questions/45649231/how-to-limit-the-title-of-wordpress-to-specific-categories
Comments