Connect with us

Tips & Tricks

How to: show/hide a widget in WordPress with jQuery

In a previous post I talked about how to show/hide a single div html code with a search inside. Today I’d like to show you how I implemented jQuery into my new theme.

As seen in the current theme, I am using jQuery to animate the show/hide or as known as the css style display: none;.

Since I am using a custom child theme on my site, and have Hybrid theme as my parent, the widgets or sidebar section is different than may be in your theme. But just apply the the style’s as follows to your theme.

First make sure that your WordPress site is calling jQuery, by plugging in this code into your header.php file above the <?php wp_head(); ?> text:

<?php wp_enqueue_script('jquery'); ?>

Then anywhere above the </head >, plug this code in:

<script type="text/javascript">
function toggleWidgets() {
	$('#primary h3.widget-title').addClass('plus');

	$('#primary h3.widget-title').click(function() {
		$(this).toggleClass('plus').toggleClass('minus').next().toggle(180);
	});

}
$(document).ready(function() {
	toggleWidgets();
}
</script>

That’s it. Pretty simple huh.

So lets go over what the code does.

$('#primary h3.widget-title').addClass('plus');

This line finds all <h3> tags with the class widget-title inside the ID parameter of #primary and adds a class of plus.

Then

$('#primary h3.widget-title').click(function() {
		$(this).toggleClass('plus').toggleClass('minus').next().toggle(180);
	});

Will apply a click function. When the H3 tag is clicked it will remove the class plus and add the class minus.

Then the code that says .next will then toggle the “next” element after the <h3> title.

Incoming search terms:

  • tutorial showhide press release text di wordpress

Random Search Terms

Title

Top Articles

powered by WassUp

Recent Posts: Fully Net Worth . com

Alex Scott Net Worth: How Rich is Alex Scott Actually?

Alex Scott Net Worth: How Rich is Alex Scott Actually?

Alex Scott is a former English footballer who is best known for her three stints at Arsenal as a right back. Moreover, she is the second most capped player in the history of the Women’s English national team with a total of 140 appearances for them. As of 2019, Alex Scott net worth is estimated […]

Reanne Evans Net Worth: How Rich is the English Snooker Player?

Reanne Evans Net Worth: How Rich is the English Snooker Player?

Reanne Evans is an English snooker player and the current World Women’s Snooker Champion. She has held the title a record 12 times, with 10 consecutive titles coming between 2005 and 2014. Evans is currently ranked number one on the World Women’s snooker Tour. As of 2019, Reanne Evans net worth is estimated to be £500,000. Evans was […]

Sasha Velour Net Worth: How Rich is the Drag Queen Actually?

Sasha Velour Net Worth: How Rich is the Drag Queen Actually?

Alexander Hedges Steinberg also known by the stage name Sasha Velour is an American drag queen and artist. Velour is best known for winning the 9th season of RuPaul’s Drag Race. As of 2019, Sasha Velour net worth is estimated to be $2.5 million. Velour was born on June 25, 1987, in Berkeley, California as the only child of Mark […]