Advertisement
fauzanjeg

Only Show Primary Category in Single Post

Aug 6th, 2021
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.48 KB | None | 0 0
  1. /* Only Show Primary Category in Single Post */
  2. function only_show_primary_category( $thelist ) {
  3.     if ( is_single() && is_singular() ) {
  4.         $cat_id = jnews_get_primary_category( get_the_ID() );
  5.         $cat = get_term( $cat_id, 'category' );
  6.         $primary_cat = '<a href="' . esc_url( get_category_link( $cat->term_id ) ) . '" rel="category tag">' . $cat->name . '</a></li>';
  7.         return $primary_cat;
  8.     }
  9.  
  10.     return $thelist;
  11. }
  12. add_filter( 'the_category', 'only_show_primary_category', 999 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement