<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>WP Snippets &#8211; In The Digital</title>
	<atom:link href="https://inthedigital.co.uk/category/wordpress/wordpress-development/wp_snippets/feed/" rel="self" type="application/rss+xml" />
	<link>https://inthedigital.co.uk</link>
	<description>Web Design, Development and Digital Marketing</description>
	<lastBuildDate>Tue, 19 Apr 2022 07:53:27 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i0.wp.com/inthedigital.co.uk/wp-content/uploads/2018/10/cropped-in-the-digital-icon-padded.png?fit=32%2C32&#038;ssl=1</url>
	<title>WP Snippets &#8211; In The Digital</title>
	<link>https://inthedigital.co.uk</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">153467252</site>	<item>
		<title>3 Ways to Improve PageSpeed by Moving jQuery to the Footer of a WordPress site.</title>
		<link>https://inthedigital.co.uk/3-ways-to-improve-pagespeed-by-moving-jquery-to-the-footer-of-a-wordpress-site/</link>
					<comments>https://inthedigital.co.uk/3-ways-to-improve-pagespeed-by-moving-jquery-to-the-footer-of-a-wordpress-site/#comments</comments>
		
		<dc:creator><![CDATA[Mervyn Booth]]></dc:creator>
		<pubDate>Tue, 27 Oct 2020 12:35:37 +0000</pubDate>
				<category><![CDATA[WP Snippets]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JS to Footer]]></category>
		<category><![CDATA[Move jQuery to footer]]></category>
		<category><![CDATA[PageSpeed]]></category>
		<guid isPermaLink="false">https://inthedigital.co.uk/?p=2383</guid>

					<description><![CDATA[Here&#8217;s how to improve your site&#8217;s rating on Google&#8217;s PageSpeed by moving render-blocking jQuery to the footer. If you&#8217;ve ever tried to improve a site&#8217;s performance on Google&#8217;s PageSpeed, you&#8217;ve probably seen that one of the &#8220;Opportunities&#8221; is to &#8220;Eliminate render-blocking resources&#8221;. These resources are typically CSS and JavaScript files. Usually, it&#8217;s not easy to [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Here&#8217;s how to improve your site&#8217;s rating on Google&#8217;s PageSpeed by moving render-blocking jQuery to the footer.</p>
<p>If you&#8217;ve ever tried to improve a site&#8217;s performance on Google&#8217;s PageSpeed, you&#8217;ve probably seen that one of the &#8220;Opportunities&#8221; is to &#8220;Eliminate render-blocking resources&#8221;. These resources are typically CSS and JavaScript files. Usually, it&#8217;s not easy to remove/move the CSS resources as this will often result in a FOUC, (<a href="https://developers.google.com/web/fundamentals/performance/critical-rendering-path/render-blocking-css#tldr" target="_blank" rel="noopener noreferrer nofollow">flash of unstyled content</a>). However, in most cases, you can get away with moving pretty much all JavaScript to the, as long as you&#8217;re not using it to style the content in the viewport (usually this is the &#8220;above-the-fold&#8221;), so let&#8217;s do that!</p>
<h2>How to Move Common JavaScript Resources to the Footer</h2>
<p>First, let&#8217;s look at the most common of JavaScript resources; <strong>jQuery</strong>. Even though jQuery isn&#8217;t as popular as it once was, it&#8217;ll be around for the foreseeable future as a vast number of JavaScript solutions are built on top of it. Plus, it&#8217;s been baked into WordPress for many years, too!</p>
<p>Here are 3 ways to move it to the footer and the logic used here can be used with other JS libraries, too.</p>
<h3>1. Add data to the enqueued scripts</h3>
<p>Using wp_scripts-&gt;<a href="https://developer.wordpress.org/reference/classes/WP_Dependencies/add_data/" target="_blank" rel="noopener noreferrer nofollow">add_data()</a>, this will add the a key/value pair (&#8216;group&#8217; and 1) to the targeted script. Note that &#8216;group&#8217; is WordPress&#8217;s way of determining if the script goes in the head or footer, 1 will put in in the footer. key/value (group/1):</p>
<pre><code class="language-php">add_action(&#039;wp_enqueue_scripts&#039;, function() {
    wp_scripts()-&gt;add_data(&#039;jquery&#039;, &#039;group&#039;, 1);
    wp_scripts()-&gt;add_data(&#039;jquery-core&#039;, &#039;group&#039;, 1);
    wp_scripts()-&gt;add_data(&#039;jquery-migrate&#039;, &#039;group&#039;, 1);
});</code></pre>
<h3>2. Dequeue existing scripts and enqueue new scripts</h3>
<p>This approach is handy if you want to change the source, such as loading from a CDN:</p>
<pre><code class="language-php">function dequeue_head_scripts_enqueue_footer_scripts() {
    wp_deregister_script(&#039;jquery&#039;);
    wp_register_script(&#039;jquery&#039;, &#039;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js&#039;, false, null, true);
    wp_enqueue_script(&#039;jquery&#039;);
}
add_action(&#039;wp_enqueue_scripts&#039;, &#039;dequeue_head_scripts_enqueue_footer_scripts&#039;, 10);</code></pre>
<h3>3. Move all scripts out of the head</h3>
<p>This way move all JS out of the head and into the footer but feels a little extreme with no granular control:</p>
<pre><code class="language-php">function move_scripts_to_footer() {
    remove_action(&#039;wp_head&#039;, &#039;wp_print_scripts&#039;);
    remove_action(&#039;wp_head&#039;, &#039;wp_print_head_scripts&#039;, 1);
    remove_action(&#039;wp_head&#039;, &#039;wp_enqueue_scripts&#039;, 1);
}
add_action(&#039;wp_enqueue_scripts&#039;, &#039;move_scripts_to_footer&#039;);</code></pre>
<h2>Conclusion</h2>
<p>In my opinion option one is the best fit (even though it feels a little ugly retrospectively changing it using &#8216;group&#8217;), as there&#8217;s no need to remove the default jQuery and you can keep tight control over which scripts are in the head and which are somewhere else. If you&#8217;d like help with this, or you have an odd edge case where none of these approaches are working, then <a href="https://inthedigital.co.uk/contact-us/">please get in touch</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://inthedigital.co.uk/3-ways-to-improve-pagespeed-by-moving-jquery-to-the-footer-of-a-wordpress-site/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2383</post-id>	</item>
		<item>
		<title>How to Remove HTML Comments from the Page Source</title>
		<link>https://inthedigital.co.uk/how-to-remove-html-comments/</link>
		
		<dc:creator><![CDATA[Mervyn Booth]]></dc:creator>
		<pubDate>Thu, 20 Feb 2020 10:09:30 +0000</pubDate>
				<category><![CDATA[WP Snippets]]></category>
		<category><![CDATA[Code snippet]]></category>
		<category><![CDATA[Removing html comment]]></category>
		<category><![CDATA[Website performance]]></category>
		<guid isPermaLink="false">https://inthedigital.co.uk/?p=1832</guid>

					<description><![CDATA[<img width="300" height="273" src="https://i0.wp.com/inthedigital.co.uk/wp-content/uploads/2020/02/remove-html-comments.png?fit=300%2C273&amp;ssl=1" class="attachment-medium size-medium wp-post-image" alt="Hot to remove HTML comments from the page&#039;s source code | In The Digital" style="float: none; margin: auto;" decoding="async" fetchpriority="high" />Many plugins (and themes) inject HTML comments into the page's source code that aren't really needed in your a live site. Here's how to remove them.]]></description>
										<content:encoded><![CDATA[<img width="300" height="273" src="https://i0.wp.com/inthedigital.co.uk/wp-content/uploads/2020/02/remove-html-comments.png?fit=300%2C273&amp;ssl=1" class="attachment-medium size-medium wp-post-image" alt="Hot to remove HTML comments from the page&#039;s source code | In The Digital" style="float: none; margin: auto;" decoding="async" /><p>Many plugins inject unnecessary HTML comments into the page&#8217;s source code. Let&#8217;s look into ways we could remove them.</p>
<h2>Why do you want HTML comments in the first place?</h2>
<p>It is a pet hate of mine that HTML gets flooded with unnecessary tripe, such as comments that relate to a section of the HTML. In WordPress loads of plugins dump this crap into the page, but why? In my opinion, as a programmer, a live site is no place for this bloat. Sure, if you feel the need to output them for debugging purposes, in development/staging, then do so &#8211; though I&#8217;m still not sure why you would, as there are proper debugging tools and techniques for that. But a live site should be optimised; only transmitting data that are necessary for the presentation and functionality of the site, so let&#8217;s try to achieve that.</p>
<h2>How can these HTML comments be removed?</h2>
<p>There’s more than one way to remove these comments, and, in some cases, the best solution is to stop them being created in the first place, but that’s not so easy when you don&#8217;t always have control over third-party code that&#8217;s creating them.</p>
<p>Yoast, a third-party plugin for SEO, have provided us with a way to achieve this. Here&#8217;s an example of how to remove comments that Yoast injects:</p>
<pre><code class="language-php">/**
* Disable Yoast&#039;s comments
*/
add_action(&#039;template_redirect&#039;, function () {
    // abort if the class doesn’t exist
    if (!class_exists(&#039;WPSEO_Frontend&#039;)) return;

    // set probable method (Yoast updates this from time-to-time)
    $method = ‘debug_mark’;

    // get instance
    $instance = WPSEO_Frontend::get_instance();

    // abort if the method doesn’t exist
    if (!method_exists($instance, $method)) return;

    // remove the method
    remove_action(‘wpseo_head’, [$instance, $method], 2);
}, 9999);</code></pre>
<p>Note that the code above is fairly volatile, as it will only work if Yoast doesn’t change the classes and hooks being called.</p>
<h2>Remove all HTML comments</h2>
<p>The above code snippet only addresses the comments in the <code>head</code> tag by a single plugin. There are techniques to remove all comments from the page. One way is to buffer all the page&#8217;s source code and use a regular expression to remove anything between <code>&lt;!--</code> and <code>--&gt;</code> before outputting the buffer&#8217;s contents. Personally, I don&#8217;t think this is a nice solution, as it will probably slow your site unless you cached the results, nonetheless, here&#8217;s a theoretical solution (untested):</p>
<pre><code class="language-php">/**
 * Callback function to remove HTML comments
 */
function buffer_callback($buffer) {
    return preg_replace(&#039;/&lt;!--(.|s)*?--&gt;/&#039;, &#039;&#039;, $buffer);
}

// start buffer at the site&#039;s head
add_action(&#039;get_header&#039;, function () {
    ob_start(&#039;buffer_callback&#039;);
});

// end buffer and flush after the WP Footer&#039;s content&#039;s been collected
add_action(&#039;wp_footer&#039;, function () {
    ob_end_flush();
});</code></pre>
<h2>Are There Other Ways to Clear Out the Noise?</h2>
<p>Whilst searching the entire document for specific strings of characters isn’t ideal, it is a solution. Alternatively, we could investigate ways that prevent the creation of them in the first place, but that&#8217;s easier said than done. If I create one I&#8217;ll share my findings.</p>
<p>If you have a suggestion or you&#8217;d like to discuss implementing something like this on your site, then please <a href="https://inthedigital.co.uk/contact-us/">get in touch</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1832</post-id>	</item>
		<item>
		<title>Extracting Thumbnails from Videos</title>
		<link>https://inthedigital.co.uk/extracting-thumbnails-from-videos-in-wordpress/</link>
		
		<dc:creator><![CDATA[Mervyn Booth]]></dc:creator>
		<pubDate>Tue, 18 Feb 2020 14:52:23 +0000</pubDate>
				<category><![CDATA[WP Snippets]]></category>
		<category><![CDATA[Code snippet]]></category>
		<category><![CDATA[Dev Tricks]]></category>
		<category><![CDATA[Feature images]]></category>
		<category><![CDATA[Thumbnails]]></category>
		<category><![CDATA[Video thumbnail]]></category>
		<guid isPermaLink="false">https://inthedigital.co.uk/?p=1848</guid>

					<description><![CDATA[<img width="300" height="253" src="https://i1.wp.com/inthedigital.co.uk/wp-content/uploads/2020/02/video-thumbnail-in-the-digital.png?fit=300%2C253&amp;ssl=1" class="attachment-medium size-medium wp-post-image" alt="Video Thumbnail | In The Digital" style="float: none; margin: auto;" decoding="async" />Recently, I&#8217;ve had a couple of projects that require thumbnails for video posts. There are plugins out there to do this, but I wanted a simple, lightweight way. Good news is, this can be achieved very easily by making use of WordPress&#8217;s WP_Embed class. /** * Maybe get thumbnail from embed * * @param string [&#8230;]]]></description>
										<content:encoded><![CDATA[<img width="300" height="253" src="https://i1.wp.com/inthedigital.co.uk/wp-content/uploads/2020/02/video-thumbnail-in-the-digital.png?fit=300%2C253&amp;ssl=1" class="attachment-medium size-medium wp-post-image" alt="Video Thumbnail | In The Digital" style="float: none; margin: auto;" decoding="async" loading="lazy" /><p>Recently, I&#8217;ve had a couple of projects that require thumbnails for video posts. There are plugins out there to do this, but I wanted a simple, lightweight way. Good news is, this can be achieved very easily by making use of WordPress&#8217;s <code>WP_Embed</code> class.</p>
<pre><code class="lang-php">/**
 * Maybe get thumbnail from embed
 *
 * @param string $string
 * @return bool
 */
function get_embed_thumbnail_from_string_maybe ($string) {

    $found = preg_match_all(&#039;|^\s*(https?://[^\s&quot;]+)\s*$|im&#039;, $string, $matches);
    if (!$found) return false;

    // nb: this can be used if we&#039;re just checking an embed exists and is supported
    //foreach ($matches[1] as $match) if (wp_oembed_get($match)) return $match;

    $embed = new WP_oEmbed();
    foreach ($matches[1] as $match) {
        if ($embed-&gt;get_html($match)) {
            return $embed-&gt;get_data($match)-&gt;thumbnail_url;
        }
    }
    return false;
}</code></pre>
<p>Place the code above in a custom functionality class or, for a crude option, dump it in the <code>functions.php</code> file and call it when a thumbnail of the first video in a string is required. An obvious use case is the blog archive page when displaying thumbnails with each post link.</p>
<p>We develop custom WordPress solutions. If you have any advanced WordPress requirements, including custom themes, plugins or theme modifications, <a href="https://inthedigital.co.uk/contact-us/">please let us know</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1848</post-id>	</item>
		<item>
		<title>How to Remove Meta Boxes from Specific Pages</title>
		<link>https://inthedigital.co.uk/how-to-remove-meta-boxes-form-specific-pages/</link>
		
		<dc:creator><![CDATA[Mervyn Booth]]></dc:creator>
		<pubDate>Tue, 02 Jul 2019 08:53:51 +0000</pubDate>
				<category><![CDATA[WP Snippets]]></category>
		<category><![CDATA[Classic Editor]]></category>
		<category><![CDATA[Code snippet]]></category>
		<category><![CDATA[Dev Tricks]]></category>
		<category><![CDATA[Hide meta boxes]]></category>
		<guid isPermaLink="false">https://inthedigital.co.uk/?p=1723</guid>

					<description><![CDATA[Sometimes you only want WordPress meta boxes, such as the permalink, on specific pages. To do so you can remove meta boxes from certain pages.]]></description>
										<content:encoded><![CDATA[<p>Here is a very simple and robust way to remove meta boxes from <em>specific</em> pages. It will remove the specified boxes from any page slugs in the array of slugs.</p>
<h2>Code to Remove Meta Boxes from Specific Pages</h2>
<pre><code class="lang-php">add_action(&#039;do_meta_boxes&#039;, function() {
    $post_id = $_GET[&#039;post&#039;] ?? ($_POST ?? false);
    global $edit_post_id;

    // just call it once - don&#039;t repeat yo&#039;self!
    if ($edit_post_id !== $post_id) {
        global $post;
        $edit_post_id = $post_id;

        // array of pages that will exclude the meta box(es)
        $exclude_on_pages = [
            &#039;home&#039;
        ];

        // remove the meta box(es) from the specific pages
        if (in_array($post-&gt;post_name, $exclude_on_pages)) {
            remove_meta_box(&#039;postimagediv&#039;, &#039;page&#039;, &#039;side&#039;);
        }
    }
});</code></pre>
<h2>Conclusion</h2>
<p>Plonk this in a plugin or your theme&#8217;s codebase and you&#8217;re good to go. Or, if you would like to know more about how you can control the meta boxes on your website, check out these posts on <a href="https://inthedigital.co.uk/how-to-move-a-wordpress-metabox/">how to move meta boxes</a> and <a href="https://inthedigital.co.uk/501-2/">how to move the Yoast meta box down</a>, or read the official WP documentation on <code>&lt;a href=&quot;https://developer.wordpress.org/reference/functions/do_meta_boxes/&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;do_meta_boxes()&lt;/a&gt;</code> and  <a href="https://developer.wordpress.org/reference/functions/remove_meta_box/" target="_blank" rel="noopener noreferrer nofollow"><code>remove_meta_boxes()</code></a> If you have any questions or would like help with WordPress related challenges, call us and we&#8217;ll gladly help.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1723</post-id>	</item>
		<item>
		<title>Remove menu link types from the WordPress menu options screen</title>
		<link>https://inthedigital.co.uk/remove-menu-link-types-from-the-wordpress-menu-options-screen/</link>
		
		<dc:creator><![CDATA[Mervyn Booth]]></dc:creator>
		<pubDate>Tue, 13 Nov 2018 12:33:16 +0000</pubDate>
				<category><![CDATA[Dev Tricks]]></category>
		<category><![CDATA[WordPress development]]></category>
		<category><![CDATA[WP Snippets]]></category>
		<category><![CDATA[nav_menus]]></category>
		<category><![CDATA[WP custom menu screen]]></category>
		<guid isPermaLink="false">https://inthedigital.co.uk/?p=1401</guid>

					<description><![CDATA[<img width="300" height="265" src="https://i2.wp.com/inthedigital.co.uk/wp-content/uploads/2018/11/custom-links-only.png?fit=300%2C265&amp;ssl=1" class="attachment-medium size-medium wp-post-image" alt="Custom links only in menu meta box" style="float: none; margin: auto;" decoding="async" loading="lazy" />On a client site, we wanted to restrict menu items to Custom Links, only. Thus remove all other menu types. The main drive behind this was to improve the user experience and reduce confusion, as the menu is only for Social Links. With a brief search yielding very little I set about coding a solution, [&#8230;]]]></description>
										<content:encoded><![CDATA[<img width="300" height="265" src="https://i2.wp.com/inthedigital.co.uk/wp-content/uploads/2018/11/custom-links-only.png?fit=300%2C265&amp;ssl=1" class="attachment-medium size-medium wp-post-image" alt="Custom links only in menu meta box" style="float: none; margin: auto;" decoding="async" loading="lazy" /><p>On a client site, we wanted to restrict menu items to Custom Links, only. Thus remove all other menu types. The main drive behind this was to improve the user experience and reduce confusion, as the menu is only for Social Links.</p>
<p>With a brief search yielding very little I set about coding a solution, by hooking into the <code>admin_head</code> action. But before we get into the code, let&#8217;s review what we need to do.</p>
<h2>Scenario: Only display Custom Links</h2>
<p><img loading="lazy" decoding="async" src="https://i0.wp.com/inthedigital.co.uk/wp-content/uploads/2018/11/menus-screen-with-only-custom-links-available.png?resize=1024%2C697&#038;ssl=1" alt="" width="1024" height="697" class="alignnone size-large wp-image-1418" alt="WordPress admin menus screen with only custom links as the available link type" srcset="https://i0.wp.com/inthedigital.co.uk/wp-content/uploads/2018/11/menus-screen-with-only-custom-links-available.png?resize=1024%2C697&amp;ssl=1 1024w, https://i0.wp.com/inthedigital.co.uk/wp-content/uploads/2018/11/menus-screen-with-only-custom-links-available.png?resize=300%2C204&amp;ssl=1 300w, https://i0.wp.com/inthedigital.co.uk/wp-content/uploads/2018/11/menus-screen-with-only-custom-links-available.png?resize=768%2C523&amp;ssl=1 768w, https://i0.wp.com/inthedigital.co.uk/wp-content/uploads/2018/11/menus-screen-with-only-custom-links-available.png?w=1400&amp;ssl=1 1400w" sizes="(max-width: 1000px) 100vw, 1000px" data-recalc-dims="1" /></p>
<p>When the current screen is the <strong>Menu</strong> screen and the selected menu is <code>social_navigation</code>, conditionally remove all link types except <strong>Custom Links</strong>. To do this we need to:<br />
&#8211; get the current screen<br />
&#8211; get the currently selected menu<br />
&#8211; check if the current menu is the <code>social_navigation</code> menu<br />
&#8211; get a list of all link types<br />
&#8211; remove all links that aren&#8217;t <strong>Custom Links</strong></p>
<h3>Get the current screen</h3>
<p>This one&#8217;s easy, we append <code>-nav-menu.php</code> to the <code>add_action</code> hook:</p>
<pre><code>add_action(&#039;admin_head-nav-menus.php&#039; ...);</code></pre>
<p>Now, the action will only fire when we&#8217;re on the menu screen of the admin area.</p>
<h3>Get the currently selected menu</h3>
<p>Though, not a straightforward as above, we can get this form the globally scoped variables, in the form of the menu&#8217;s <code>id</code>:</p>
<pre><code>global $nav_menu_selected_id;</code></pre>
<p>Next we&#8217;ll use this to check if the current menu is <code>social_navigation</code>.</p>
<h3>Check if the current menu is the Social Menu</h3>
<p>This is a little fiddly, as we need to compare the <code>id</code> from <code>$nav_menu_selected_id</code> with the <code>id</code> of the Social Menu. So first, lets get a list of available menus, then we can compare their <code>id</code>&#8216;s with <code>$nav_menu_selected_id</code>. For this I&#8217;ll grab another <code>global</code> variable:</p>
<pre><code>global $menu_locations;</code></pre>
<p>Then compare the <code>id</code> of <code>social_navigation</code> with <code>$nav_menu_selected_id</code> to see if we&#8217;re currently viewing the Social Menu.</p>
<h3>Get a list of all link types</h3>
<p>Another <code>global</code> variable comes to the rescue here, <code>$wp_meta_boxes</code>. This is a multidimensional array of all meta-boxes, including the <code>nav-menus</code>. So everything we need is in <code>$wp_meta_boxes[&#039;nav-menus&#039;][&#039;side&#039;]</code> (we only need <code>side</code> as all <code>nav-menu</code> meta-boxes are of <code>side</code> context):</p>
<pre><code class="lang-php">global $wp_meta_boxes;
// $wp_meta_boxes[&#039;nav-menus&#039;][&#039;side&#039;] holds all the nav-menus</code></pre>
<h3>Remove all links that aren&#8217;t Custom Links</h3>
<p>All we need to do is loop through the <code>$wp_meta_boxes[&#039;nav-menus&#039;][&#039;side&#039;]</code> array and conditionally remove the link type if its <code>id</code> doesn&#8217;t match <code>add-custom-links</code>:</p>
<pre><code class="lang-php">foreach ($wp_meta_boxes[&#039;nav-menus&#039;][&#039;side&#039;] as $nav_menus) {
    foreach ($nav_menus as $nav_id =&gt; $nav_menu) {
        if ($nav_id !== &#039;add-custom-links&#039;) {
            remove_meta_box($nav_id, &#039;nav-menus&#039;, &#039;side&#039;);
        }
    }
}</code></pre>
<p>And that&#8217;s it. Here&#8217;s the full code, copy an paste this into your <code>functions.php</code> file, or better still, a functionality plugin, modify it to suit your needs and you&#8217;re good to go:</p>
<pre><code>/**
 * Remove nav menu meta-box links from the &#039;social_navigation&#039; menu
 *
 * NB:  all nav menus are $context &#039;side&#039;
 *
 *      use var_dump(wp_list_pluck($nav_menus,&#039;id&#039;))
 *      inside the outer loop to display a list of all link type IDs
 */
function custom_remove() {
    global $wp_meta_boxes, $nav_menu_selected_id, $menu_locations;

    // store the id of the social menu
    $social_nav = $menu_locations[&#039;social_navigation&#039;] ?? false;

    // if the current menu id is the social menu&#039;s then let&#039;s do this
    if ($social_nav === $nav_menu_selected_id) {

        // loop through the &#039;core&#039; and &#039;default&#039; arrays 
        foreach ($wp_meta_boxes[&#039;nav-menus&#039;][&#039;side&#039;] as $nav_menus) {

            // loops through their menus
            foreach ($nav_menus as $nav_id =&gt; $nav_menu) {

                // remove the menu&#039;s meta-box if it isn&#039;t the one we want to keep
                if ($nav_id !== &#039;add-custom-links&#039;) {
                    remove_meta_box($nav_id, &#039;nav-menus&#039;, &#039;side&#039;);
                }
            }
        }
    }
}
add_action(&#039;admin_head-nav-menus.php&#039;, __NAMESPACE__.&#039;\\custom_remove&#039;, 10);</code></pre>
<p><em>Note</em>: We namespace our environment for conflict avoidance, hence the <code>__NAMESPACE__</code> prepended function call.</p>
<h2>Conclusion</h2>
<p>This is a really nice bit of code for improving the user experience and keeping control of your menus. I especially like it because it&#8217;s pretty lightweight, too!</p>
<p>If you have any questions, or have a particular programming challenge, especially with WordPress, please get in touch and we&#8217;ll gladly help, as we&#8217;re seasoned in WP &#8211; designing and building custom themes and plugins. And love a challenge.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1401</post-id>	</item>
		<item>
		<title>How to break long words using CSS @supports</title>
		<link>https://inthedigital.co.uk/how-to-break-long-words-using-css-supports/</link>
		
		<dc:creator><![CDATA[Mervyn Booth]]></dc:creator>
		<pubDate>Wed, 07 Nov 2018 09:05:48 +0000</pubDate>
				<category><![CDATA[Dev Tricks]]></category>
		<category><![CDATA[WP Snippets]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS layout]]></category>
		<category><![CDATA[overflow-wrap]]></category>
		<category><![CDATA[word-wrapping]]></category>
		<guid isPermaLink="false">https://inthedigital.co.uk/?p=1255</guid>

					<description><![CDATA[<img width="151" height="300" src="https://i1.wp.com/inthedigital.co.uk/wp-content/uploads/2018/11/overflowing-text-on-mobile-device.gif?fit=151%2C300&amp;ssl=1" class="attachment-medium size-medium wp-post-image" alt="Overflowing text on mobile device" style="float: none; margin: auto;" decoding="async" loading="lazy" />Recently, I had an odd scenario where wrapping long text needed either word-wrap, overflow-wrap or word-break to achieve the same overflow pattern across different browsers. To arrive at a suitable solution I opted to use @supports to maintain control of the declarations. What is @supports? @supports is a feature query, whose associated block of statments [&#8230;]]]></description>
										<content:encoded><![CDATA[<img width="151" height="300" src="https://i1.wp.com/inthedigital.co.uk/wp-content/uploads/2018/11/overflowing-text-on-mobile-device.gif?fit=151%2C300&amp;ssl=1" class="attachment-medium size-medium wp-post-image" alt="Overflowing text on mobile device" style="float: none; margin: auto;" decoding="async" loading="lazy" /><p>Recently, I had an odd scenario where wrapping long text needed either <code>word-wrap</code>, <code>overflow-wrap</code> or <code>word-break</code> to achieve the same overflow pattern across different browsers. To arrive at a suitable solution I opted to use <code>@supports</code> to maintain control of the declarations.</p>
<h2>What is @supports?</h2>
<p><code>@supports</code> is a <em>feature query</em>, whose associated block of statments only get triggered when the client (i.e. browser) supports the feature(s), <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@supports" rel="noopener noreferrer nofollow" target="_blank">as described on MDN</a>. Here&#8217;s a simple example:</p>
<pre><code class="lang-css">/*
 * Test if client supports display: grid 
 */
@supports (display: grid) {
  display: grid;
  float: none;
}</code></pre>
<p>The example above is pretty self explanatory:<br />
<em>Process the enclosed block of declarations if the control declaration is know by the client.</em></p>
<h2>The Problem &#8211; text that is too long for the width of its containing box</h2>
<p>This is a common webpage layout hurdle, and one that completely breaks the page if not handled with due consideration. Take for example a scenario I&#8217;ve seen time and again: horizontal scroll on a mobile device, where the content overflowing to the right of the viewport is completly unstyled, as depicted below <em>(NB: the site in the demo isn&#8217;t broken &#8211; we&#8217;re just demostrating the issue)</em>:</p>
<p><a data-toggle="collapse" href="#demoImage">Toggle Demo</a></p>
<figure id="demoImage" class="collapse in text-center">
<img loading="lazy" decoding="async" src="https://i1.wp.com/inthedigital.co.uk/wp-content/uploads/2018/11/overflowing-text-on-mobile-device.gif?resize=320%2C634&#038;ssl=1" alt="Overflowing text on mobile device" width="320" height="634" class="alignnone size-full wp-image-1269" data-recalc-dims="1" /><figcaption style="padding:1rem;"><em>The perils of untamed text</em></figcaption></figure>
<h2>Using @supports to handle long words</h2>
<p>This is an ugly problem. And one that&#8217;s often addressed with a combination of <code>hyphens</code>(inc. prefixes) and <code>word-break</code>. Unfortunately, there are times when they don&#8217;t cut it. For example, when a hypen isn&#8217;t a desirable aethestic, or not all words want breaking.</p>
<p>What I was looking for was a way to break long words, but not hypenate them, and defintely don&#8217;t break words that can just fit on the next line. So, through trial and error, I found the following to work perfectly for our use-case, which only passes the relevant declarations to browsers that support them:</p>
<pre><code class="lang-css">/*
 * Break long words
 * Only break words that are too long to fit on one line
 * Uses @supports
 */
h1, h2, h3, h4, article {
  /* doesn&#039;t recognise underscored_words on all browsers */
  word-wrap: break-word; 
}
@supports (overflow-wrap: break-word) and (not (word-break: break-word)) {
  /* doesn&#039;t recognise underscored_words on all browsers, use if word-break: break-word isn&#039;t supported */
  h1, h2, h3, h4, article {
      overflow-wrap: break-word;
  }
}
@supports (word-break: break-word) {
  /* use if supported */
  h1, h2, h3, h4, article {
      word-break: break-word;
  }
}
</code></pre>
<h2>Conclusion</h2>
<p>Using <code>@supports</code> is an elegant way to make us of the tools that fit each of the browsers we need to code for. Sometimes, more-often-than-not, we don&#8217;t need to use it. In the case above I could have just let the browser&#8217;s decide if they could or couldn&#8217;t understand the declarations, but the way I&#8217;ve structured it gives me confidence that I&#8217;ll get the desired outcomes from the declarations I&#8217;ve tested. Plus it gave me a reason to talk about <code>@supports</code>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1255</post-id>	</item>
		<item>
		<title>Conditionally enqueue scripts and stylesheets on specific pages</title>
		<link>https://inthedigital.co.uk/conditionally-enqueue-scripts-styles-specific-pages/</link>
		
		<dc:creator><![CDATA[Mervyn Booth]]></dc:creator>
		<pubDate>Sat, 03 Nov 2018 13:01:33 +0000</pubDate>
				<category><![CDATA[WP Snippets]]></category>
		<category><![CDATA[Dev Tricks]]></category>
		<category><![CDATA[Contact Form 7]]></category>
		<category><![CDATA[Dequeuing scripts]]></category>
		<category><![CDATA[Enqueuing scripts]]></category>
		<guid isPermaLink="false">https://inthedigital.co.uk/?p=1142</guid>

					<description><![CDATA[There are many use-cases where scripts and stylesheets only need to be loaded on certain pages. One such example would be to only load the JavaScript and CSS stylesheets for Contact Form 7 (a lightweight contact form plugin) on the contact page. This article will demonstrate how to conditionally load the JS and CSS for [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>There are many use-cases where scripts and stylesheets only need to be loaded on certain pages. One such example would be to only load the JavaScript and CSS stylesheets for <em>Contact Form 7</em> (<a href="https://en-gb.wordpress.org/plugins/contact-form-7/" target="_blank" rel="noopener noreferrer nofollow">a lightweight contact form plugin</a>) on the <a href="https://inthedigital.co.uk/contact-us/" target="_blank" rel="noopener noreferrer">contact page</a>.</p>
<p>This article will demonstrate how to conditionally load the JS and CSS for CF7, but the concept could be adapted to apply to other plugins.</p>
<h2>Preventing/dequeuing the script and styles</h2>
<p><small>NB: For the rest of this article I&#8217;ll refer to scripts and styles collectively as <em>assets</em>.</small></p>
<p>The first thing we need to do is stop the default action of the assets being loaded on all pages. A generic way of achieving this would be to find the assets in the <a href="https://codex.wordpress.org/Global_Variables" rel="noopener noreferrer nofollow" target="_blank"><code>$wp_styles</code> and <code>$wp_scripts</code> variable</a>. However, CF7 provides a filter that can be accessed, for which we can just return false, thus not enqueuing anything:</p>
<pre><code class="lang-php">/**
 * Do NOT enqueue CF7 scripts and styles
 */
add_filter(&#039;wpcf7_load_js&#039;, &#039;__return_false&#039;);
add_filter(&#039;wpcf7_load_css&#039;, &#039;__return_false&#039;);</code></pre>
<p>Now the assets will not load on <em>any</em> pages. Our next task is to specify the pages we&#8217;d like to load them on.</p>
<h2>Conditionally loading assets</h2>
<p>For this particular scenario the assets only need to be loaded on the contact page. WordPress has a suitable function to achieve this, <code>is_page()</code>. This function takes the page id, name or an array of the page ids and names. <a href="https://contactform7.com/loading-javascript-and-stylesheet-only-when-it-is-necessary/" rel="noopener noreferrer nofollow" target="_blank">Contact Form 7 states that the functions to load the assets</a> back in need to be called before the <code>wp_head()</code> hook, therefore we&#8217;ll call them in <code>get_header()</code>, which is fired just before:</p>
<pre><code class="lang-php">/**
 * Action: Load Contact Form 7 assets into get_header
 */
add_action(&#039;get_header&#039;, function() {
    // Load assets only on contact pages.
    if (is_page([&#039;contact&#039;, &#039;contact-us&#039;])) {
        if (function_exists(&#039;wpcf7_enqueue_scripts&#039;)) wpcf7_enqueue_scripts();
        if (function_exists(&#039;wpcf7_enqueue_styles&#039;)) wpcf7_enqueue_styles();
    }
});</code></pre>
<p>As controlled by the outer if statement, these assets are only being called when the page slug is either &#8216;contact&#8217; or &#8216;contact-us&#8217;. To extend this to enqueue the assets on other pages simply include the pages in the is_page() arguments, or modify the expression to include further conditionals. For example, assume the sidebar for the blog pages had a CF7 form widget, the control statement could be modified to check if the sidebar is active:</p>
<pre><code>if (is_page([&#039;contact&#039;, &#039;contact-us&#039;]) || is_active_sidebar(&#039;blog-sidebar&#039;))</code></pre>
<h2>Wrapping it up</h2>
<p>There are many ways this code could be modified to meet specific requirements, just add it to your theme&#8217;s <code>functions.php</code> file (or a functionality plugin) and modify as necessary. The examples in this article are specific to Contact Form 7, for a more generic approach to enqueuing and dequeueing JavaScript and stylesheets refer to <a href="https://codex.wordpress.org/Plugin_API/Action_Reference/wp_enqueue_scripts" rel="noopener noreferrer nofollow" target="_blank">WordPress&#8217;s <code>wp_enqueue_scripts()</code> documentation</a>, or <a href="https://inthedigital.co.uk/contact-us/">get in touch with our seasoned WordPress developers</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1142</post-id>	</item>
		<item>
		<title>Using LD+JSON Schema to Enhance SEO for Blog Posts</title>
		<link>https://inthedigital.co.uk/using-ld-json-enhance-blog-posts-seo/</link>
		
		<dc:creator><![CDATA[Mervyn Booth]]></dc:creator>
		<pubDate>Thu, 01 Nov 2018 08:03:40 +0000</pubDate>
				<category><![CDATA[Search Engine Optimisation]]></category>
		<category><![CDATA[WP Snippets]]></category>
		<category><![CDATA[Code snippet]]></category>
		<category><![CDATA[Dev Tricks]]></category>
		<category><![CDATA[JSONLD]]></category>
		<category><![CDATA[schema.org]]></category>
		<guid isPermaLink="false">https://inthedigital.co.uk/?p=1124</guid>

					<description><![CDATA[<img width="300" height="186" src="https://i2.wp.com/inthedigital.co.uk/wp-content/uploads/2018/11/enhancing-seo-with-ldjson.jpg?fit=300%2C186&amp;ssl=1" class="attachment-medium size-medium wp-post-image" alt="enhancing seo with ld+json" style="float: none; margin: auto;" decoding="async" loading="lazy" />Schema markup helps search engines understand your content by describing its primary purpose, in a machine-friendly way. The most recent, and in my opinion, the easiest to maintain, is ld+json, which is contained in a script tag, proving the search engines with the key data. What does ld+json markup look like? The best way to [&#8230;]]]></description>
										<content:encoded><![CDATA[<img width="300" height="186" src="https://i2.wp.com/inthedigital.co.uk/wp-content/uploads/2018/11/enhancing-seo-with-ldjson.jpg?fit=300%2C186&amp;ssl=1" class="attachment-medium size-medium wp-post-image" alt="enhancing seo with ld+json" style="float: none; margin: auto;" decoding="async" loading="lazy" /><p>Schema markup helps search engines understand your content by describing its primary purpose, in a machine-friendly way. The most recent, and in my opinion, the easiest to maintain, is <b>ld+json</b>, which is contained in a <code>script</code> tag, proving the search engines with the key data.</p>
<h2>What does ld+json markup look like?</h2>
<p>The best way to explain what ld+json markup looks like is with example code, based on the <b><a href="https://schema.org/Article" target="_blank" rel="noopener noreferrer nofollow">Article</a></b> type. Below is the code for this post:</p>
<pre><code class="language-json">{
    &quot;@context&quot;: &quot;http://schema.org&quot;,
    &quot;@type&quot;: &quot;BlogPosting&quot;,
    &quot;headline&quot;: &quot;the post title&quot;,
    &quot;datePublished&quot;: &quot;the post date&quot;,
    &quot;image&quot;: {
        &quot;@type&quot;: &quot;ImageObject&quot;,
        &quot;url&quot;: &quot;the post thumbnail&quot;
    },
    &quot;description&quot; : &quot;the post description/excerpt&quot;
}</code></pre>
<p>As you can see, this is super easy, so get marking up! But you may want to double-check that your post has a featured image and an excerpt, otherwise <code>image.url</code> and <code>description</code> will be empty. One easy way to overcome these is to check a thumbnail exists and use WordPress&#8217;s <code>wp_trim_excert()</code> to create an excerpt from the post&#8217;s content. Feel free to get in touch if you would a helping hand, as we&#8217;re seasoned WordPress developers.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1124</post-id>	</item>
		<item>
		<title>Nesting CSS Media Queries</title>
		<link>https://inthedigital.co.uk/nesting-css-media-queries/</link>
		
		<dc:creator><![CDATA[Mervyn Booth]]></dc:creator>
		<pubDate>Sun, 28 Oct 2018 08:47:31 +0000</pubDate>
				<category><![CDATA[Dev Tricks]]></category>
		<category><![CDATA[WP Snippets]]></category>
		<category><![CDATA[Code snippet]]></category>
		<category><![CDATA[CSS]]></category>
		<guid isPermaLink="false">https://inthedigital.co.uk/?p=879</guid>

					<description><![CDATA[Processing styling rules based on certain criteria, such as viewport width, is achieved using the @media conditional&#160;group rules.&#160;As of October 2018, all modern browsers support nested @media queries. What&#8217;s a @media query? Here&#8217;s a simple example of a media query to make the text 10% bigger on devices with a screen (viewport) wider than 768px [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Processing styling rules based on certain criteria, such as viewport width, is achieved using the <code>@media</code> conditional&nbsp;group rules.&nbsp;As of October 2018, all modern browsers support <em>nested</em> <code>@media</code> queries.</p>
<h2>What&#8217;s a @media query?</h2>
<p>Here&#8217;s a simple example of a media query to make the text 10% bigger on devices with a screen (viewport) wider than 768px (the viewport width of the original iPad):</p>
<pre><code class="lang-css">@media (min-width: 768px) {
  p, div {
    font-size: 1.1em;
  }
}
</code></pre>
<p>This is a pretty self-explanatory snippet of code:</p>
<blockquote><p>When the width is greater than 768 pixels relatively resize the font size of paragraph and div tags to 110% of their current size.</p></blockquote>
<p>Cool, right? But what about if we also wanted to increase the font-size of&nbsp;<code>div</code> tags by a different amount when the height is greater than 1024px? One solution is to use&nbsp;<strong>nested&nbsp;</strong>media queries.</p>
<h2>What are nested @media queries?</h2>
<p>Taking the problem described above, here&#8217;s an example of nested media queries to make the text within the <code>paragraph</code> and <code>div</code> tags 10% bigger on devices wider than 768px, but with a nested condition to apply an additional rule to <code>div</code> tags when the viewport height is&nbsp;<em>also</em>&nbsp;at least 1024px:</p>
<pre><code class="lang-css">@media (min-width: 768px) {
  p, div {
    font-size: 1.1em;
  }

  @media (min-height: 1024px) {
    div {
      font-size: 1.15em;
    }
  }
}</code></pre>
<p>How about that?! The query is still pretty self-explanatory:</p>
<blockquote><p>When the width is greater than 768 pixels relatively resize the font size of paragraph and div tags to 110% of the current size. However, if the height is greater than 1024 pixels relatively resize the font size of div tags to <em>115%</em> of the current size.</p></blockquote>
<p>Note: there are other ways to achieve this, without nesting the media queries, most obviously is by having separate query groups for <code>paragraph</code> and <code>div</code>&nbsp;tags.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">879</post-id>	</item>
		<item>
		<title>Adding Feature Images to the WordPress RSS Feed</title>
		<link>https://inthedigital.co.uk/873-2/</link>
		
		<dc:creator><![CDATA[Mervyn Booth]]></dc:creator>
		<pubDate>Fri, 26 Oct 2018 13:18:29 +0000</pubDate>
				<category><![CDATA[Dev Tricks]]></category>
		<category><![CDATA[WordPress development]]></category>
		<category><![CDATA[WP Snippets]]></category>
		<category><![CDATA[Code snippet]]></category>
		<guid isPermaLink="false">https://inthedigital.co.uk/?p=873</guid>

					<description><![CDATA[The WordPress RSS feed is great. We use it with third-party services, such as MailChimp. One key datum that isn&#8217;t included in the feeds by default is the featured image for posts (and pages). This article will address that with a simple &#8216;action&#8216; hook that adds the featured image to the item&#8217;s feed. /** * [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>The WordPress RSS feed is great. We use it with third-party services, such as MailChimp. One key datum that isn&#8217;t included in the feeds by default is the featured image for posts (and pages). This article will address that with a simple &#8216;<code>action</code>&#8216; hook that adds the featured image to the item&#8217;s feed.</p>
<pre><code class="lang-php">/**
 * Filter: Add feature image to RSS feeds
 *
 * @param $content string   the content
 * @return string           the potentially modified content
 */
function rss_featured_image($content) {
    global $post;

    // if the isn&#039;t an associated featured image, then return just return the content
    if (!has_post_thumbnail()) return $content;

    // featured image layout
    $styling = [&#039;style&#039; =&gt; &#039;float: none; margin: auto;&#039;];

    // add a filter to return null for srcset
    add_filter( &#039;wp_calculate_image_srcset_meta&#039;, &#039;__return_null&#039; );
    $featured_image = get_the_post_thumbnail($post-&gt;ID, &#039;medium&#039;, $styling);

    // remove the above filter
    remove_filter( &#039;wp_calculate_image_srcset_meta&#039;, &#039;__return_null&#039; );

    // return the featured image and the $content
    return $featured_image . $content;
}

add_filter(&#039;the_excerpt_rss&#039;, __NAMESPACE__.&#039;\\rss_featured_image&#039;);
add_filter(&#039;the_content_feed&#039;, __NAMESPACE__.&#039;\\rss_featured_image&#039;);
</code></pre>
<h2>Using a plugin or WP developer</h2>
<p>Don&#8217;t fancy getting you hands dirty with code? Search the WP plugins repo, or get in touch for further help.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">873</post-id>	</item>
	</channel>
</rss>
