Quantcast
Channel: User Michael - WordPress Development Stack Exchange
Viewing all articles
Browse latest Browse all 44

Answer by Michael for Custom HTML in specific category single page and its descendant categories

$
0
0

A few changes to your code:

  • Changed the action hook to wp_head.
  • Removed the false 'pluggable' wrapping of your function.

if ( ! function_exists( 'post_is_in_descendant_category' ) ) {    function post_is_in_descendant_category( $cats, $_post = null ) {        foreach ( (array) $cats as $cat ) {            // get_term_children() accepts integer ID only            $descendants = get_term_children( (int) $cat, 'category' );            if ( $descendants && in_category( $descendants, $_post ) )                return true;        }        return false;    }}function hiderelated(){  if ( in_category( 168 ) || post_is_in_descendant_category( 168 ) ) {  ?><style>    .relatednews { display: none; }</style><?php  }}add_action( 'wp_head', 'hiderelated' );

Viewing all articles
Browse latest Browse all 44

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>