snipt

Ctrl+h for KB shortcuts

PHP

category id in body and post class

1
2
3
4
5
6
7
8
function category_id_class($classes) {
    global $post;
	foreach((get_the_category($post->ID)) as $category)
		$classes [] = 'cat-' . $category->cat_ID . '-id';
		return $classes;
}
add_filter('post_class', 'category_id_class');
add_filter('body_class', 'category_id_class');
https://snipt.net/embed/c1b0891b9f3db867394a2e0e3018042a/
/raw/c1b0891b9f3db867394a2e0e3018042a/
c1b0891b9f3db867394a2e0e3018042a
php
PHP
8
2019-07-16T18:13:33
True
False
False
/api/public/snipt/39716/
category-id-in-body-and-post-class
<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="x">function category_id_class($classes) {</span> </span><span id="L-2"><a name="L-2"></a><span class="x"> global $post;</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> foreach((get_the_category($post-&gt;ID)) as $category)</span> </span><span id="L-4"><a name="L-4"></a><span class="x"> $classes [] = &#39;cat-&#39; . $category-&gt;cat_ID . &#39;-id&#39;;</span> </span><span id="L-5"><a name="L-5"></a><span class="x"> return $classes;</span> </span><span id="L-6"><a name="L-6"></a><span class="x">}</span> </span><span id="L-7"><a name="L-7"></a><span class="x">add_filter(&#39;post_class&#39;, &#39;category_id_class&#39;);</span> </span><span id="L-8"><a name="L-8"></a><span class="x">add_filter(&#39;body_class&#39;, &#39;category_id_class&#39;);</span> </span></pre></div> </td></tr></table>
functions.php, php, wordpress

PHP

custom admin login logo

1
2
3
4
5
6
function custom_login_logo() {
    echo '<style type="text/css">
	h1 a { background-image: url('.get_bloginfo('template_directory').'/images/custom-login-logo.png) !important; }
	</style>';
}
add_action('login_head', 'custom_login_logo');
https://snipt.net/embed/ccb4ab5fa80f68e9da102fb128ff8ff8/
/raw/ccb4ab5fa80f68e9da102fb128ff8ff8/
ccb4ab5fa80f68e9da102fb128ff8ff8
php
PHP
6
2019-07-14T08:33:04
True
False
False
/api/public/snipt/39715/
custom-admin-login-logo
<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="x">function custom_login_logo() {</span> </span><span id="L-2"><a name="L-2"></a><span class="x"> echo &#39;&lt;style type=&quot;text/css&quot;&gt;</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> h1 a { background-image: url(&#39;.get_bloginfo(&#39;template_directory&#39;).&#39;/images/custom-login-logo.png) !important; }</span> </span><span id="L-4"><a name="L-4"></a><span class="x"> &lt;/style&gt;&#39;;</span> </span><span id="L-5"><a name="L-5"></a><span class="x">}</span> </span><span id="L-6"><a name="L-6"></a><span class="x">add_action(&#39;login_head&#39;, &#39;custom_login_logo&#39;);</span> </span></pre></div> </td></tr></table>
functions.php, php, wordpress

JavaScript

New window jQuery

1
2
3
4
5
6
$(function(){
    $('a.new-window').click(function(){
        window.open(this.href);
        return false;
    });
});
https://snipt.net/embed/1c0b23595efc3aa216d5bd3a187d35af/
/raw/1c0b23595efc3aa216d5bd3a187d35af/
1c0b23595efc3aa216d5bd3a187d35af
js
JavaScript
6
2019-07-08T08:02:26
True
False
False
/api/public/snipt/12711/
new-window-jquery
<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="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="s1">&#39;a.new-window&#39;</span><span class="p">).</span><span class="nx">click</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span> </span><span id="L-3"><a name="L-3"></a> <span class="nb">window</span><span class="p">.</span><span class="nx">open</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">href</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">return</span> <span class="kc">false</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a> <span class="p">});</span> </span><span id="L-6"><a name="L-6"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
accssibility, jquery

CSS

link like button

1
2
3
4
a:active {
  position: relative;
  top: 1px;
}
https://snipt.net/embed/c34cb256b3739d00aa2a198e18285c32/
/raw/c34cb256b3739d00aa2a198e18285c32/
c34cb256b3739d00aa2a198e18285c32
css
CSS
4
2019-07-14T09:17:55
True
False
False
/api/public/snipt/11915/
link-like-button
<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="nt">a</span><span class="nd">:active</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="nb">position</span><span class="o">:</span> <span class="nb">relative</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a> <span class="nb">top</span><span class="o">:</span> <span class="m">1px</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>
css

Java

CDATA

/* <![CDATA[ */
/* ]]> */
https://snipt.net/embed/d9ef6bda8fb69f1c7e277bd1c2cd21d1/
/raw/d9ef6bda8fb69f1c7e277bd1c2cd21d1/
d9ef6bda8fb69f1c7e277bd1c2cd21d1
java
Java
2
2019-07-14T17:21:44
True
False
False
/api/public/snipt/4473/
cdata
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cm">/* &lt;![CDATA[ */</span> </span><span id="L-2"><a name="L-2"></a><span class="cm">/* ]]&gt; */</span> </span></pre></div> </td></tr></table>
javascript, xhtml