How to Exclude Certain Tags from Single Post Tags in Kadence

Disclosure: This post may contain affiliate links – meaning I get a commission if you decide to make a purchase through my links, at no cost to you.

In the previous tutorial, I showed how Elements feature of Kadence can be used to add an affiliate disclosure automatically above the entry content on all posts that have a specific tag.

Let’s say you decide to use the “Affiliate Disclosure” tag for this, it will be shown at the bottom of single posts tagged “Affiliate Disclosure” and you most probably do not want that.

The current version of Kadence does not include an option in the Customizer to exclude specific tags from appearing on single posts. While we could simply use CSS and hide the unwanted ones, it is better to not print them in the HTML output rather than sweeping them under the rug.

So the way to go about this is to disable “Show Post Tags” in the Customizer, copy the code from Kadence theme files, modify it to exclude certain tags and hook this to kadence_single_after_inner_content.

Step 1

In the Customizer go to Blog Posts > Single Post Layout and turn off “Show Post Tags”.

Step 2

Add the following either in child theme‘s functions.php or as a Code Snippet:

add_action( 'kadence_single_after_inner_content', 'custom_entry_tags' );
/**
 * Exclude certain tags from single post tags.
 */
function custom_entry_tags() {
	if ( 'post' !== get_post_type() ) {
		return;
	} ?>

	<footer class="entry-footer">
		<?php
		$tags = get_the_tags();
		if ( ! is_array( $tags ) ) {
			return;
		}
		?>
		<div class="entry-tags">
			<span class="tags-links">
				<span class="tags-label screen-reader-text">
					<?php echo esc_html__( 'Post Tags:', 'kadence' ); ?>
				</span>
				<?php
				$exclude_these_term_ids = array(
				   229,
				);
				foreach ( $tags as $tag_item ) {
					if ( ! in_array( $tag_item->term_id, $exclude_these_term_ids ) ) {
						$tag_link = get_tag_link( $tag_item->term_id );
						echo '<a href=' . esc_url( $tag_link ) . ' title="' . esc_attr( $tag_item->name ) . '" class="tag-link tag-item-' . esc_attr( $tag_item->slug ) . '" rel="tag"><span class="tag-hash">#</span>' . esc_html( $tag_item->name ) . '</a>';
					}
				}
				?>
			</span>
		</div><!-- .entry-tags -->
	</footer><!-- .entry-footer -->
<?php }

In the above set the ID of the tag you want to exclude in

$exclude_these_term_ids = array(
	229,
);

To exclude multiple tags, separate them by commas like so:

$exclude_these_term_ids = array(
	229,
	423,
);

References

/themes/kadence/template-parts/content/entry_tags.php

/themes/kadence/template-parts/content/entry_footer.php

/themes/kadence/template-parts/content/single-entry.php

/themes/kadence/template-parts/content/single.php

https://wordpress.stackexchange.com/a/59482/14380

Similar Posts

  • Kadence Child Theme

    Kadence is a highly customizable theme even for beginners and non-coders thanks to its rich and elaborate settings in the WordPress Customizer. For advanced users that want to make any changes in the theme files though it makes sense to use a child theme as the active theme since it allows for template overriding. The…

  • Related Posts in Kadence

    Kadence theme comes with a built-in Customizer setting for showing similar (related) posts on single posts. Let’s see how it actually works under the hood. /kadence/template-parts/content/single-entry.php has: i.e., if the current page is a singular post and if Customizer > Blog Posts > Single Post Layout > Show Related Posts is enabled, then load template-parts/content/entry_related.php….

  • Kadence Membership Price Increase

    The developer of Kadence recently posted an update about Kadence beta, price changes and their rollout plan in their Facebook group. Here is a summary: Features available in the beta of “Kadence Theme Pro”, a plugin that extends Kadence theme with premium features and addons: Header addons, Kadence elements, WooCommerce addons. Beta can be used…

  • Hooked Elements in Kadence

    One of the features that Kadence Theme Pro adds to Kadence theme is called Hooked Elements which provides an interface to build an element using the WordPress Gutenberg editor and hook it to one of the several locations on your pages so it appears exactly where and when you want. A sample use case of…

  • Custom Fonts in WordPress

    This tutorial provides the steps to set up and use custom fonts in WordPress. Step 1 Upload your font file (typically in .ttf or .otf format) at Font Squirrel to generate the webfont. Step 2 Extract the generated zip file and upload the .woff and .woff2 files to your child theme directory’s fonts directory. If…

Leave a Reply

Your email address will not be published. Required fields are marked *