Advertisement
pusatdata

WP Trik: Membatasi Huruf Judul pada Kategori Tertentu

Aug 17th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. KODE UNTUK KESELURUHAN JUDUL PADA HOME, KATEGORI, TAG
  2. ====================================================
  3. function titleLimitChar($title){
  4. if(strlen($title) > 30 && !(is_single()) && !(is_page())){ // not in single post page and page.
  5. $title = substr($title,0,30) . "..";
  6. }
  7. return $title;
  8. }
  9. add_filter( 'the_title', 'titleLimitChar' );
  10.  
  11. KODE HANYA UNTUK KATEGORI TERTENTU (SATU, DUA, ATAU LEBIH KATEGORI)
  12. ============================
  13. function titleLimitChar($title){
  14. if(is_category( '9' )){
  15. if(strlen($title) > 30 && !(is_single()) && !(is_page())){ // not in single post page and page.
  16. $title = substr($title,0,30) . "..";
  17. }
  18. return $title;
  19. }else{
  20. return $title;
  21. }
  22.  
  23.  
  24. }
  25. add_filter( 'the_title', 'titleLimitChar' );
  26.  
  27. PENJELASAN:
  28.  
  29. in the is_category() you use category id, category name and catgory-slug etc.
  30.  
  31. For Multiple categories just pass array in the parameter as
  32.  
  33. array( 9, 'blue-cheese', 'Stinky Cheeses' )
  34. Other uses to check specific category or categories as below from the WordPress developer portal.
  35.  
  36. is_category();
  37. // When any Category archive page is being displayed.
  38.  
  39. is_category( '9' );
  40. // When the archive page for Category 9 is being displayed.
  41.  
  42. is_category( 'Stinky Cheeses' );
  43. // When the archive page for the Category with Name "Stinky Cheeses" is being displayed.
  44.  
  45. is_category( 'blue-cheese' );
  46. // When the archive page for the Category with Category Slug "blue-cheese" is being displayed.
  47.  
  48. is_category( array( 9, 'blue-cheese', 'Stinky Cheeses' ) );
  49.  
  50. SUMBER: https://stackoverflow.com/questions/45649231/how-to-limit-the-title-of-wordpress-to-specific-categories
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement