Showing widget items in sidebar conditionally

Hi support, I would like some of the items in my sidebar widget to show/hide depending on tags of the post the reader is viewing. I already have code that does this for items in the post by this code:

add_filter ('the_content', 'add_AdToPost', 11 );
function add_AdToPost ( $content ) {
	if(!has_tag('Småspararguiden granskar finansbranschen')) {
		$Ad = do_shortcode('<p><a id="article_footer_finansterapi" href="http://www.smaspararguiden.se/oberoende-radgivning/"><img src="https://www.smaspararguiden.se/wp-content/uploads/2023/05/banner-finansterapi.png" alt="Oberoende rådgiving med Småspararguiden"></a></p>');
	} else {
		$Ad = do_shortcode('<p><a id="article_footer_donation" href="https://smaspararguiden.typeform.com/to/fPRexP"><img src="https://www.smaspararguiden.se/wp-content/uploads/2022/10/banner-crowdfunding.jpg" alt="Gillar du att vi granskar branschen? Stötta oss!"></a></p>');
	}
	return is_singular('post') ? $content.$Ad : $content;
}

How do I go about to edit widget items with the same logic?

Hey @smaspararguiden,

Thank you for reaching out!

We appreciate your query regarding customizing the items in your sidebar widget based on the tags of the post being viewed.

However, I regret to inform you that this particular customization falls outside the scope of our theme support. Our primary focus is to assist with issues directly related to the features and functionalities of our theme.

To achieve the desired functionality, we suggest seeking the assistance of third-party developers. Alternatively, you may explore the option of using One, a service we offer where we can address questions that extend beyond the capabilities of our theme.

Thank you for your understanding.

Thanks and sorry for not knowing what your support is limited to. I found a plugin called “Content aware” that did the trick for me.

Hi @smaspararguiden,

Glad to know that you are able to find a solution for this.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.