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.
The article provides a comprehensive guide to driving traffic to your website, highlighting 21 effective…
While e-commerce is projected to account for more than $6.5 trillion in sales by 2023,…
The analysis highlights the significance of link-building in SEO, revealing that most websites neglect backlinks,…
Hey everyone, I've got two copies of Blog Blazers that I want to give away…
101 of the best blogging tools in 2024. Having the best blogging tools continues to…
In WordPress, when you use wp_page_menu your anchor attribute's usually carry a title with the…
View Comments
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?
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?
Example links?
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 =-.
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.