snipt

Ctrl+h for KB shortcuts

PHP

Add theme suggestion by view_mode, field_name and bundle for fields

1
2
3
4
5
6
7
8
<?php

function MYTHEME_preprocess_field(&$variables, $hook) {
    $element = $variables['element'];

    // Add specific suggestions that can override the default implementation.
    $variables['theme_hook_suggestions'][] = 'field__' . $element['#bundle'] . '__' . $element['#view_mode'] . '__' . $element['#field_name'];
}
https://snipt.net/embed/d0b74622f7856b3a8041f90cf1a8f390/
https://snipt.net/raw/d0b74622f7856b3a8041f90cf1a8f390/
d0b74622f7856b3a8041f90cf1a8f390
php
PHP
8
2016-09-25T22:34:50
True
False
False
Jan 24, 2013 at 09:55 AM
/api/public/snipt/54392/
add-theme-suggestion-by-view_mode-field_name-and-bundle-for-fields
<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 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><span id="L-3"><a name="L-3"></a><span class="k">function</span> <span class="nf">MYTHEME_preprocess_field</span><span class="p">(</span><span class="o">&amp;</span><span class="nv">$variables</span><span class="p">,</span> <span class="nv">$hook</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="nv">$element</span> <span class="o">=</span> <span class="nv">$variables</span><span class="p">[</span><span class="s1">&#39;element&#39;</span><span class="p">];</span> </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a> <span class="c1">// Add specific suggestions that can override the default implementation.</span> </span><span id="L-7"><a name="L-7"></a> <span class="nv">$variables</span><span class="p">[</span><span class="s1">&#39;theme_hook_suggestions&#39;</span><span class="p">][]</span> <span class="o">=</span> <span class="s1">&#39;field__&#39;</span> <span class="o">.</span> <span class="nv">$element</span><span class="p">[</span><span class="s1">&#39;#bundle&#39;</span><span class="p">]</span> <span class="o">.</span> <span class="s1">&#39;__&#39;</span> <span class="o">.</span> <span class="nv">$element</span><span class="p">[</span><span class="s1">&#39;#view_mode&#39;</span><span class="p">]</span> <span class="o">.</span> <span class="s1">&#39;__&#39;</span> <span class="o">.</span> <span class="nv">$element</span><span class="p">[</span><span class="s1">&#39;#field_name&#39;</span><span class="p">];</span> </span><span id="L-8"><a name="L-8"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
"drupal 7", bundle, field, field_name, hook, suggestion, template, view_mode

PHP

Add Header Image

1
2
3
4
5
// Add Header Image
function thematic_logo_image() {
 echo '<a href="'.get_bloginfo('url').'" title="'.get_bloginfo('name').'" ><span id="header-image"></span></a>';
}
add_action('thematic_header','thematic_logo_image',6);
https://snipt.net/embed/9075549bac6289faf544580a7cadbadf/
https://snipt.net/raw/9075549bac6289faf544580a7cadbadf/
9075549bac6289faf544580a7cadbadf
php
PHP
5
2016-09-26T07:48:04
True
False
False
/api/public/snipt/32871/
add-header-image
<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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="x">// Add Header Image</span> </span><span id="L-2"><a name="L-2"></a><span class="x">function thematic_logo_image() {</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> echo &#39;&lt;a href=&quot;&#39;.get_bloginfo(&#39;url&#39;).&#39;&quot; title=&quot;&#39;.get_bloginfo(&#39;name&#39;).&#39;&quot; &gt;&lt;span id=&quot;header-image&quot;&gt;&lt;/span&gt;&lt;/a&gt;&#39;;</span> </span><span id="L-4"><a name="L-4"></a><span class="x">}</span> </span><span id="L-5"><a name="L-5"></a><span class="x">add_action(&#39;thematic_header&#39;,&#39;thematic_logo_image&#39;,6);</span> </span></pre></div> </td></tr></table>
hook, thematic, wordpress

PHP

footer credit

1
2
3
4
5
6
7
// footer credit

function my_footer($thm_footertext) {
	$thm_footertext = 'Copyright &copy; 2011 Mayhem Design Studio. <a href="http://www.mayhemdesignstudio.com">mayhemdesignstudio.com</a> powered by <a href="http://www.wordpress.org">WordPress</a>.';
	return $thm_footertext;
}
add_filter('thematic_footertext', 'my_footer');
https://snipt.net/embed/66e51fe7f0eb52cf00464635a63ea945/
https://snipt.net/raw/66e51fe7f0eb52cf00464635a63ea945/
66e51fe7f0eb52cf00464635a63ea945
php
PHP
7
2016-09-26T07:48:08
True
False
False
/api/public/snipt/32867/
footer-credit
<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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="x">// footer credit</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="x">function my_footer($thm_footertext) {</span> </span><span id="L-4"><a name="L-4"></a><span class="x"> $thm_footertext = &#39;Copyright &amp;copy; 2011 Mayhem Design Studio. &lt;a href=&quot;http://www.mayhemdesignstudio.com&quot;&gt;mayhemdesignstudio.com&lt;/a&gt; powered by &lt;a href=&quot;http://www.wordpress.org&quot;&gt;WordPress&lt;/a&gt;.&#39;;</span> </span><span id="L-5"><a name="L-5"></a><span class="x"> return $thm_footertext;</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;thematic_footertext&#39;, &#39;my_footer&#39;);</span> </span></pre></div> </td></tr></table>
hook, thematic, wordpress
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.