Advertisement
fauzanjeg

Category Selector for Single Post || Example Change Logo for Spesific Single Post by Category Slug

Nov 10th, 2021
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. /* Category Selector for Single Post || Example Change Logo for Spesific Single Post by Category Slug */
  2. if ( is_single() && is_singular() ) {
  3.     $post          = get_post();
  4.     $post_cat      = get_the_category( $post->ID );
  5.     $primary_cat   = jnews_get_primary_category( $post->ID );
  6.     $primary_cat   = get_category( $primary_cat );
  7.     $post_cat_slug = array();
  8.  
  9.     array_push( $post_cat, $primary_cat );
  10.  
  11.     /* Get Category Slug */
  12.     foreach ( $post_cat as $cat ) {
  13.         array_push( $post_cat_slug, $cat->slug );
  14.     }
  15.  
  16.     if ( in_array( 'mobile', $post_cat_slug ) ) { /*
  17.         `mobile` is slug category you want to change logo for spesific single post */
  18.         /* Logo URL Link  */
  19.         $logo             = '/wp-content/uploads/2021/11/90-Radio-logo.png';
  20.         $logo_retina      = '/wp-content/uploads/2021/11/90-Radio-logo@x2.png';
  21.         $alt              = '/wp-content/uploads/2021/11/90-Radio-logo.png';
  22.         $logo_dark        = '/wp-content/uploads/2021/11/90-Radio-logo-dark.png';
  23.         $logo_retina_dark = '/wp-content/uploads/2021/11/90-Radio-logo-dark@x2.png';
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement