Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

JavaScript

Toggle class on hover

1
2
3
4
5
6
$('.btn').hover(function(){
		$(this).addClass('hover');
	}, 
    function(){
		$(this).removeClass('hover');
	});
https://snipt.net/embed/ef004478383f2d1c85b0e95a2408d336/
https://snipt.net/raw/ef004478383f2d1c85b0e95a2408d336/
ef004478383f2d1c85b0e95a2408d336
js
JavaScript
6
2016-12-08T03:26:58
True
False
False
Jan 31, 2014 at 04:09 AM
/api/public/snipt/109801/
toggle-class-on-hover
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;.btn&#39;</span><span class="p">).</span><span class="nx">hover</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">addClass</span><span class="p">(</span><span class="s1">&#39;hover&#39;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a> <span class="p">},</span> </span><span id="L-4"><a name="L-4"></a> <span class="kd">function</span><span class="p">(){</span> </span><span id="L-5"><a name="L-5"></a> <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">removeClass</span><span class="p">(</span><span class="s1">&#39;hover&#39;</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">});</span> </span></pre></div> </td></tr></table>
button, class, css, hover, jquery

JavaScript

Jquery Submenu - active - remove and add

1
2
3
4
$("#submenu01").on("click", "a:not(.active)", function ( event ) {
    $(".active", event.delegateTarget).removeClass("active");
    $(this).addClass("active");
});
https://snipt.net/embed/af6aade45f123b2636cd4b7b8558e28f/
https://snipt.net/raw/af6aade45f123b2636cd4b7b8558e28f/
af6aade45f123b2636cd4b7b8558e28f
js
JavaScript
5
2016-12-08T03:27:16
True
False
False
Aug 05, 2013 at 12:29 PM
/api/public/snipt/72025/
jquery-submenu-active-remove-and-add
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#submenu01&quot;</span><span class="p">).</span><span class="nx">on</span><span class="p">(</span><span class="s2">&quot;click&quot;</span><span class="p">,</span> <span class="s2">&quot;a:not(.active)&quot;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span> <span class="nx">event</span> <span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;.active&quot;</span><span class="p">,</span> <span class="nx">event</span><span class="p">.</span><span class="nx">delegateTarget</span><span class="p">).</span><span class="nx">removeClass</span><span class="p">(</span><span class="s2">&quot;active&quot;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">addClass</span><span class="p">(</span><span class="s2">&quot;active&quot;</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
active, add, addClass, class, jquery, remove

PHP

Add custom body classes to custom Wordpress templates

1
2
3
4
5
6
7
8
<?php
	//Add custom body classes to the chosen templates, for example, custom page templates that are used actually as post archives. 
	//Usage: add_filter('body_class','browser_body_class'); in the template file code
	function browser_body_class($classes = '') {
		$classes[] = 'page-customtemplate-archive';
		return $classes;
	}
?>
https://snipt.net/embed/125eaba16eacbfcae00cf66c3bb1e53e/
https://snipt.net/raw/125eaba16eacbfcae00cf66c3bb1e53e/
125eaba16eacbfcae00cf66c3bb1e53e
php
PHP
8
2016-11-10T23:45:11
True
False
True
Jul 27, 2013 at 10:37 AM
/api/public/snipt/69875/
add-custom-body-classes-to-custom-wordpress-templates
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> <span class="c1">//Add custom body classes to the chosen templates, for example, custom page templates that are used actually as post archives. </span> </span><span id="L-3"><a name="L-3"></a> <span class="c1">//Usage: add_filter(&#39;body_class&#39;,&#39;browser_body_class&#39;); in the template file code</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">function</span> <span class="nf">browser_body_class</span><span class="p">(</span><span class="nv">$classes</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-5"><a name="L-5"></a> <span class="nv">$classes</span><span class="p">[]</span> <span class="o">=</span> <span class="s1">&#39;page-customtemplate-archive&#39;</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a> <span class="k">return</span> <span class="nv">$classes</span><span class="p">;</span> </span><span id="L-7"><a name="L-7"></a> <span class="p">}</span> </span><span id="L-8"><a name="L-8"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
class, css, functions.php, template, wordpress

PHP

Strip excessive classes from custom menu markup in Wordpress

1
2
3
4
5
6
7
8
<?php
add_filter('nav_menu_css_class', 'css_attributes_filter', 100, 1); //makes classes in individual items of a custom menu dissappear
	add_filter('nav_menu_item_id', 'css_attributes_filter', 100, 1);
	add_filter('page_css_class', 'css_attributes_filter', 100, 1);
	function css_attributes_filter($var) {
		return is_array($var) ? array_intersect($var, array('current-menu-item','current-menu-ancestor')) : '';
	}
?>
https://snipt.net/embed/54c565e079eb0c9c6d91a127a8f0c394/
https://snipt.net/raw/54c565e079eb0c9c6d91a127a8f0c394/
54c565e079eb0c9c6d91a127a8f0c394
php
PHP
8
2016-11-27T16:44:26
True
False
True
Jul 27, 2013 at 10:24 AM
/api/public/snipt/69871/
strip-excessive-classes-from-custom-menu-markup-in-wordpress
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="nx">add_filter</span><span class="p">(</span><span class="s1">&#39;nav_menu_css_class&#39;</span><span class="p">,</span> <span class="s1">&#39;css_attributes_filter&#39;</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span> <span class="c1">//makes classes in individual items of a custom menu dissappear</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">add_filter</span><span class="p">(</span><span class="s1">&#39;nav_menu_item_id&#39;</span><span class="p">,</span> <span class="s1">&#39;css_attributes_filter&#39;</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="nx">add_filter</span><span class="p">(</span><span class="s1">&#39;page_css_class&#39;</span><span class="p">,</span> <span class="s1">&#39;css_attributes_filter&#39;</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">function</span> <span class="nf">css_attributes_filter</span><span class="p">(</span><span class="nv">$var</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-6"><a name="L-6"></a> <span class="k">return</span> <span class="nb">is_array</span><span class="p">(</span><span class="nv">$var</span><span class="p">)</span> <span class="o">?</span> <span class="nb">array_intersect</span><span class="p">(</span><span class="nv">$var</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;current-menu-item&#39;</span><span class="p">,</span><span class="s1">&#39;current-menu-ancestor&#39;</span><span class="p">))</span> <span class="o">:</span> <span class="s1">&#39;&#39;</span><span class="p">;</span> </span><span id="L-7"><a name="L-7"></a> <span class="p">}</span> </span><span id="L-8"><a name="L-8"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
class, css, functions.php, wordpress
Copyrighted, illegal, or inappropriate content? Email [email protected].