Advertisement
pusatdata

WP Trik: Cara Membatasi Judul WP di Home/Category

Jun 21st, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. paste this code i function.php
  2.  
  3. ========================
  4. KODE UMUM/SEMUA KATEGORI
  5. ========================
  6.  
  7. function titleLimitChar($title){
  8. if(strlen($title) > 55 && !(is_single()) && !(is_page())){ // not in single post page and page.
  9. $title = substr($title,0,55) . "..";
  10. }
  11. return $title;
  12. }
  13. add_filter( 'the_title', 'titleLimitChar' );
  14.  
  15. ========================
  16. KODE UNTUK SPESIFIK KATEGORI >> sumber: https://stackoverflow.com/questions/45649231/how-to-limit-the-title-of-wordpress-to-specific-categories/45649542#45649542
  17. ========================
  18.  
  19. function titleLimitChar($title){
  20. if(is_category( '9' )){
  21. if(strlen($title) > 30 && !(is_single()) && !(is_page())){ // not in single post page and page.
  22. $title = substr($title,0,30) . "..";
  23. }
  24. return $title;
  25. }else{
  26. return $title;
  27. }
  28.  
  29.  
  30. }
  31. add_filter( 'the_title', 'titleLimitChar' );
  32.  
  33. Penjelasan:
  34. in the is_category() you use category id, category name and catgory-slug etc.
  35.  
  36. For Multiple categories just pass array in the parameter as
  37.  
  38. array( 9, 'blue-cheese', 'Stinky Cheeses' )
  39. Other uses to check specific category or categories as below from the WordPress developer portal.
  40.  
  41. is_category();
  42. // When any Category archive page is being displayed.
  43.  
  44. is_category( '9' );
  45. // When the archive page for Category 9 is being displayed.
  46.  
  47. is_category( 'Stinky Cheeses' );
  48. // When the archive page for the Category with Name "Stinky Cheeses" is being displayed.
  49.  
  50. is_category( 'blue-cheese' );
  51. // When the archive page for the Category with Category Slug "blue-cheese" is being displayed.
  52.  
  53. is_category( array( 9, 'blue-cheese', 'Stinky Cheeses' ) );
  54.  
  55. Tambahan sumber: https://developer.wordpress.org/reference/functions/is_category/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement