Connect with us
The intuitive design of ledger live desktop wallet software simplifies the process of managing and trading cryptocurrencies, offering users a secure and user-friendly experience within the decentralized finance ecosystem.

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.

Published

on

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.

Continue Reading
9 Comments

9 Comments

  1. Rolograaf

    July 29, 2009 at 5:59 am

    Tried this, saw the javascript in the source of my blog, but the plus class was not added and click function not activated. Any idears what I could have done wrong?

    • Alik

      September 14, 2009 at 7:27 am

      Same problem here. In Firebug th script is there, but the class is not added to h3 widget class inside div ID primary.

      Any ideas?

      • Austin

        September 15, 2009 at 12:40 pm

        Example links?

        • Alik

          September 18, 2009 at 5:40 pm

          http://accio.website.pl/ozo/
          code is working now (I think so 😉 ) but the CSS class/definition for hide/unhide panels is missing (?).
          .-= Alik´s last blog ..Import blogu z blox.pl do WordPress =-.

          • Chris

            September 28, 2009 at 9:22 pm

            Doesn’t work for me. I don’t see the class added. I have the last jquery installed, I even tried the noConflict just in case and nothing.

  2. Pingback: 30 Tutorials Combining Both Wordpress and jQuery : Speckyboy Design Magazine

  3. Pingback: 30 Tutorials Combining Both Wordpress and jQuery | Coyot [at] CanalCoffee.com : WordPress

  4. Pingback: 30 tutorial para utilizar jQuery en nuestro Wordpress | code

  5. Pingback: 20+ jQuery and Wordpress Tutorials – A Match Made in Heaven

You must be logged in to post a comment Login

Leave a Reply

Themes

Fixing plugins not compatible with hybrid 0.4.2

Published

on

Hey everyone, as you may have noticed I have a running on the site. While everything almost everything moved over smoothly, there was an issue with how my parent theme striped text in typography. This caused some plugins, like cformsII to not be allowed to print to the screen. Justin had helped to find a fix to filter the hybrid_typography function.

Originally this function filtered out and changed some text that would not validate as XHTML. This had to be removed by running a new function in the child theme’s function.php file.

add_action('init', 'remove_typography');

function remove_typography() {
	remove_filter('the_content', 'hybrid_typography', 11);
}
Continue Reading

Plugins

Add the twittar plugin for WordPress w/ comment threading

Published

on

I talked about the Twittar plugin in a previous post. But learned that the read me text file was only useful for installing the necessary php code into WordPress themes that don’t have comment threading enabled.

Since most new themes past version 2.7, pull the comments section from functions.php file, that is where you have to edit the avatars in order to show the twittar settings.

First open you functions.php, and look for a line of code that says:

function custom_comment()

This is where your new comments are pulled from when you have the threaded comments enabled.

Now just find <?php echo get_avatar( $comment, $args['avatar_size'] ); ?> & replace with <?php twittar(70, "", "", "avatar avatar-70 photo", 1, "R"); ?>. Keep in mind that you will need to edit the Twittar setting to fit your site.

Continue Reading

Tips & Tricks

Styling your ordered & unordered list items into 2 columns

Published

on

In a previous post I showed you how to create a custom widget, then I showed you how to create a widget for your monthly archives, and limit the month’s that show. I am showing the past 4 months in my widget at this time.

One of my readers: Alex asked:

How did you make the archives widget to show the dates separately into two columns?

Now I will show you a CSS trick to create this effect:

First we will give the unordered list a width of 100%:

ul#archives {
	width:110%;
	}

Then we will style the <li> nested inside.

ul#archives li {
	display:inline;
	float:left;
	width:120px;
	}

And that is it. Please make sure that you clear the float after your closing </ul>.

Continue Reading

Random Search Terms

Title

Recent Posts: Fully Net Worth . com

Pete Buttigieg Net Worth: 5 Facts You Should Know

Pete Buttigieg Net Worth: 5 Facts You Should Know

Pete Buttigieg is the mayor of South Bend, Indiana. He is also an American war veteran and a former consultant. In the recent days, Buttigieg has been growing his name with him announcing candidacy for the Presidential election in 2020. Then President Obama called him as one of four Democrats who represented the future of […]

Yandy Smith Net Worth

Yandy Smith Net Worth

Yandy Smith Net Worth. The American celeb Yandy Smith has a net value of $15 million. She is a reality TV star and music producer. Yandy started her professional career working in the entertainment industry. She started working as an executive assistant in a company called Violator Management. Some of her clients include high-profile musicians […]

Jasmine Luv Net Worth: How Rich is the YouTube star?

Jasmine Luv Net Worth: How Rich is the YouTube star?

Jasmine Luv is an American Youtuber who is known for her comedic videos which are very relatable to the fans. This has helped her to build a fan following on Instagram of over 1.3 million and is also working on a Youtube Channel that has already crossed 110k subscribers. As of 2019, Jasmine Luv net […]

Jasmine Roth Net Worth: How Rich is Jasmine Roth Actually?

Jasmine Roth Net Worth: How Rich is Jasmine Roth Actually?

Jasmine Roth is the founder of Built Custom Homes which focuses on custom designs for new construction projects. Moreover, Roth is also a television personality being the host of the show called Hidden Potential. As of 2019, Jasmine Roth net worth is estimated to be $1.5 million. Roth grew up in Virginia and since her […]

Trending