fauzanjeg

Hide Featured Image for Spesific Category

Nov 8th, 2021 (edited)
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. /* Hide Featured Image for Spesific Category */
  2. function hide_featured_image_for_spesific_category( $default, $post_id, $key ) {
  3.     if ( is_single() && is_singular() ) {
  4.         if ( 'jnews_primary_category.id' !== $key ) {
  5.             $post = get_post();
  6.             if ( is_object( $post ) && $post->ID ) {
  7.                 $post_cat      = get_the_category( $post->ID );
  8.                 $primary_cat   = jnews_get_primary_category( $post->ID );
  9.                 $primary_cat   = get_category( $primary_cat );
  10.                 $post_cat_slug = array();
  11.  
  12.                 array_push( $post_cat, $primary_cat );
  13.  
  14.                 /* Get Category Slug */
  15.                 foreach ( $post_cat as $cat ) {
  16.                     if ( ! is_wp_error( $cat ) && isset( $cat->slug ) ) {
  17.                         array_push( $post_cat_slug, $cat->slug );
  18.                     }
  19.                 }
  20.  
  21.                 if ( in_array( 'gaming', $post_cat_slug ) ) { /* `gaming` is slug category you want to disable Featured Image */
  22.                     if ( 'jnews_single_post.override_template' === $key ) {
  23.                         return true;
  24.                     }
  25.                     if ( 'jnews_single_post.override.0.show_featured' === $key ) {
  26.                         return false;
  27.                     }
  28.                 }
  29.             }
  30.         }
  31.     }
  32.  
  33.     return $default;
  34. }
  35. add_filter( 'jeg_vp_metabox', 'hide_featured_image_for_spesific_category', null, 3 );
Add Comment
Please, Sign In to add comment