<?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/"
	>

<channel>
	<title>Code Snippets Archive - Bill Erickson</title>
	<atom:link href="https://www.billerickson.net/code/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.billerickson.net/code/</link>
	<description>WordPress Design and Development</description>
	<lastBuildDate>Thu, 14 May 2026 13:18:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>

<image>
	<url>https://www.billerickson.net/wp-content/uploads/2018/11/cropped-favicon-150x150.png</url>
	<title>Code Snippets Archive - Bill Erickson</title>
	<link>https://www.billerickson.net/code/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Close Comments</title>
		<link>https://www.billerickson.net/code/close-comments/</link>
		
		<dc:creator><![CDATA[Bill Erickson]]></dc:creator>
		<pubDate>Thu, 14 May 2026 13:18:39 +0000</pubDate>
				<guid isPermaLink="false">https://www.billerickson.net/?post_type=code&#038;p=8688</guid>

					<description><![CDATA[<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/close-comments/">Close Comments</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-code"><code>add_filter( 'comments_open', '__return_false' );

add_action( 'comment_form_comments_closed', function() { 
  echo '&lt;p>Comments are temporarily closed while we perform maintenance on the website.&lt;/p>'; 
} );</code></pre>
<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/close-comments/">Close Comments</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Password protected zip through terminal</title>
		<link>https://www.billerickson.net/code/password-protected-zip-through-terminal/</link>
		
		<dc:creator><![CDATA[Bill Erickson]]></dc:creator>
		<pubDate>Mon, 30 Dec 2024 23:04:19 +0000</pubDate>
				<guid isPermaLink="false">https://www.billerickson.net/?post_type=code&#038;p=8677</guid>

					<description><![CDATA[<p>If you want to zip the &#8220;foobar&#8221; directory into &#8220;foobar.zip&#8221;, use this: It will then ask you to enter password, then verify password.</p>
<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/password-protected-zip-through-terminal/">Password protected zip through terminal</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>If you want to zip the &#8220;foobar&#8221; directory into &#8220;foobar.zip&#8221;, use this:</p>



<pre class="wp-block-code"><code>zip -er foobar.zip foobar</code></pre>



<p>It will then ask you to enter password, then verify password. </p>
<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/password-protected-zip-through-terminal/">Password protected zip through terminal</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Logo dimensions as CSS variable</title>
		<link>https://www.billerickson.net/code/logo-dimensions-as-css-variable/</link>
		
		<dc:creator><![CDATA[Bill Erickson]]></dc:creator>
		<pubDate>Thu, 03 Feb 2022 22:37:10 +0000</pubDate>
				<guid isPermaLink="false">https://www.billerickson.net/?post_type=code&#038;p=8628</guid>

					<description><![CDATA[<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/logo-dimensions-as-css-variable/">Logo dimensions as CSS variable</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-code"><code>$logo = shortcode_parse_atts( cwp_icon( &#91; 'icon' => 'logo', 'group' => 'logo', 'size' => false, 'force' => true ] ) );
if ( ! empty( $logo&#91;'viewbox'] ) ) {
  $dimensions = explode( ' ', $logo&#91;'viewbox'] );
  $style = 'body { --cwp-logo-width: ' . $dimensions&#91;2] . 'px; --cwp-logo-height: ' . $dimensions&#91;3] . 'px;}';
  wp_add_inline_style( 'theme-style', $style );
}
</code></pre>
<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/logo-dimensions-as-css-variable/">Logo dimensions as CSS variable</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Disable loading=&#8221;lazy&#8221; on images in first block</title>
		<link>https://www.billerickson.net/code/disable-loadinglazy-on-images-in-first-block/</link>
		
		<dc:creator><![CDATA[Bill Erickson]]></dc:creator>
		<pubDate>Thu, 14 Oct 2021 15:03:38 +0000</pubDate>
				<guid isPermaLink="false">https://www.billerickson.net/?post_type=code&#038;p=8622</guid>

					<description><![CDATA[<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/disable-loadinglazy-on-images-in-first-block/">Disable loading=&#8221;lazy&#8221; on images in first block</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-code"><code>add_filter(
	'pre_render_block',
	function( $pre_render ) {
		global $cwp_block;
		if ( empty( $cwp_block ) ) {
			$cwp_block = 1;
		} else {
			$cwp_block++;
		}
		return $pre_render;
	}
);

add_filter(
	'wp_lazy_loading_enabled',
	function( $default ) {
		global $cwp_block;
		if ( 1 === $cwp_block ) {
			$default = false;
		}
		return $default;
	}
);</code></pre>
<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/disable-loadinglazy-on-images-in-first-block/">Disable loading=&#8221;lazy&#8221; on images in first block</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Set max srcset image to 2x</title>
		<link>https://www.billerickson.net/code/set-max-srcset-image-to-2x/</link>
		
		<dc:creator><![CDATA[Bill Erickson]]></dc:creator>
		<pubDate>Thu, 07 Jan 2021 19:06:01 +0000</pubDate>
				<guid isPermaLink="false">https://www.billerickson.net/?post_type=code&#038;p=8604</guid>

					<description><![CDATA[<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/set-max-srcset-image-to-2x/">Set max srcset image to 2x</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-code"><code>/**
 * Max srcset image size
 */
function be_max_srcset_image_size( $max_width, $sizes ) {
	return 2 * $sizes&#91;0];
}
add_filter( 'max_srcset_image_width', 'be_max_srcset_image_size', 10, 2 );
</code></pre>
<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/set-max-srcset-image-to-2x/">Set max srcset image to 2x</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Author archive link pointed to about page</title>
		<link>https://www.billerickson.net/code/author-archive-link-pointed-to-about-page/</link>
		
		<dc:creator><![CDATA[Bill Erickson]]></dc:creator>
		<pubDate>Thu, 03 Sep 2020 15:31:05 +0000</pubDate>
				<guid isPermaLink="false">https://www.billerickson.net/?post_type=code&#038;p=8406</guid>

					<description><![CDATA[<p>The author name at the top of a post typically points to that author&#8217;s archive page (example). You can use the author_link filter to point it to any URL you&#8217;d like.&#8230;</p>
<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/author-archive-link-pointed-to-about-page/">Author archive link pointed to about page</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>The author name at the top of a post typically points to that author&#8217;s archive page (example). You can use the <code>author_link</code> filter to point it to any URL you&#8217;d like.</p>



<p>In this case, I have every author link pointed to the site&#8217;s /about/ page. You could use the <code>$author_id</code> parameter to use a different URL based on the user (ex: linking to that user&#8217;s Website field from their profile).</p>



<pre class="wp-block-code"><code>// Author URL goes to about page
add_filter( 'author_link', function( $link, $author_id ) {
	return trailingslashit( home_url( 'about' ) );
}, 10, 2 );
</code></pre>



<p></p>
<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/author-archive-link-pointed-to-about-page/">Author archive link pointed to about page</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>WP Recipe Maker &#8211; query for posts with videos in recipe card</title>
		<link>https://www.billerickson.net/code/wprm-video-post-query/</link>
		
		<dc:creator><![CDATA[Bill Erickson]]></dc:creator>
		<pubDate>Mon, 03 Aug 2020 15:32:15 +0000</pubDate>
				<category><![CDATA[WP Recipe Maker]]></category>
		<guid isPermaLink="false">https://www.billerickson.net/?post_type=code&#038;p=8393</guid>

					<description><![CDATA[<p>This first runs a query for recipes that have videos, then loops through those recipes and adds the &#8220;parent post id&#8221; to an array. This is the post to which&#8230;</p>
<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/wprm-video-post-query/">WP Recipe Maker &#8211; query for posts with videos in recipe card</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This first runs a query for recipes that have videos, then loops through those recipes and adds the &#8220;parent post id&#8221; to an array. This is the post to which the recipe was attached. We then query for those posts.</p>



<pre class="wp-block-code"><code>$recipes = new WP_Query( &#91;
	'post_type' => 'wprm_recipe',
	'posts_per_page' => 8,
	'fields' => 'ids',
	'update_post_term_cache' => false,
	'ignore_sticky_posts' => true,
	'no_found_rows' => true,
	'meta_query' => &#91;
		&#91;
			'key' => 'wprm_video_embed',
			'value' => '',
			'compare' => '!=',
		]
	]
]);

if( empty( $recipes->posts ) )
	return;

$post_ids = &#91;];
foreach( $recipes->posts as $recipe_id ) {
	$post_id = get_post_meta( $recipe_id, 'wprm_parent_post_id', true );
	if( !empty( $post_id ) &amp;&amp; 'post' === get_post_type( $post_id ) )
		$post_ids&#91;] = intval( $post_id );
}

$posts = new WP_Query( &#91;
	'post__in'	=> $post_ids,
	'orderby'	=> 'post__in',
]);</code></pre>



<p></p>
<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/wprm-video-post-query/">WP Recipe Maker &#8211; query for posts with videos in recipe card</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Track PWA install in Google Analytics</title>
		<link>https://www.billerickson.net/code/track-pwa-install-in-google-analytics/</link>
		
		<dc:creator><![CDATA[Bill Erickson]]></dc:creator>
		<pubDate>Fri, 12 Jun 2020 22:25:18 +0000</pubDate>
				<guid isPermaLink="false">https://www.billerickson.net/?post_type=code&#038;p=8354</guid>

					<description><![CDATA[<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/track-pwa-install-in-google-analytics/">Track PWA install in Google Analytics</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-code"><code>window.addEventListener('appinstalled', (event) => {
	if ( 'function' === typeof ga ) {
		// Default GA.
		ga( 'send', 'event', 'pwa', 'install );
	} else if ( 'function' === typeof __gaTracker ) {
		// MonsterInsights.
		__gaTracker( 'send', 'event', 'pwa', 'install' );
	}
});</code></pre>
<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/track-pwa-install-in-google-analytics/">Track PWA install in Google Analytics</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>WPForms Order Number</title>
		<link>https://www.billerickson.net/code/wpforms-order-number/</link>
		
		<dc:creator><![CDATA[Bill Erickson]]></dc:creator>
		<pubDate>Thu, 04 Jun 2020 18:32:50 +0000</pubDate>
				<guid isPermaLink="false">https://www.billerickson.net/?post_type=code&#038;p=8351</guid>

					<description><![CDATA[<p>Generate sequential order numbers for WPForms submissions. Add a hidden field to your form named &#8220;Order Number&#8221; and add a CSS class of order-number. When the form is submitted, the&#8230;</p>
<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/wpforms-order-number/">WPForms Order Number</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Generate sequential order numbers for WPForms submissions.</p>



<figure class="wp-block-image alignwide size-full"><img fetchpriority="high" decoding="async" width="1200" height="630" src="https://www.billerickson.net/wp-content/uploads/2020/06/sequential-order-number.jpg" alt="" class="wp-image-8353" srcset="https://www.billerickson.net/wp-content/uploads/2020/06/sequential-order-number.jpg 1200w, https://www.billerickson.net/wp-content/uploads/2020/06/sequential-order-number-768x403.jpg 768w, https://www.billerickson.net/wp-content/uploads/2020/06/sequential-order-number-1168x613.jpg 1168w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<p>Add a hidden field to your form named &#8220;Order Number&#8221; and add a CSS class of <code>order-number</code>. When the form is submitted, the following code will update that field to have a sequential order number.</p>



<p>It stores the order number as a site-option and increments the number on successful form submission. It creates a separate option for each form so you can have multiple order forms with their own sequential numbering. </p>



<p>If you want a single sequential sequence used for all forms, set <code>$use_single_sequence = true;</code>.</p>



<p>I&#8217;m formatting the order number to have eight digits (ex: <code>00000001</code>). You can change the number of digits by changing the &#8220;8&#8221; in <code>%08d</code>&nbsp;at the end.</p>



<pre class="wp-block-code"><code>
/**
 * WPForms, Sequential Order Number
 * @author Bill Erickson
 * @link https://www.billerickson.net/code/wpforms-sequential-order-number
 */
function be_wpforms_order_number( $fields, $entry, $form_data ) {
	$use_single_sequence = false;
	$order_field_id = false;

	foreach( $form_data['fields'] as $field ) {
		if( empty( $field['css'] ) )
			continue;

		$classes = explode( ' ', $field['css'] );
		if( in_array( 'order-number', $classes ) )
			$order_field_id = $field['id'];
	}
	if( empty( $order_field_id ) )
		return $fields;

	$option = $use_single_sequence ? 'be_wpforms_order' : 'be_wpforms_' . $form_data['id'] . '_order';
	$order = intval( get_option( $option ) );
	$order++;
	update_option( $option, $order );

	$fields[ $order_field_id ]['value'] = sprintf( '%08d', $order );
	return $fields;
}
add_filter( 'wpforms_process_filter', 'be_wpforms_order_number', 10, 3 );
</code></pre>
<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/wpforms-order-number/">WPForms Order Number</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Rename category taxonomy</title>
		<link>https://www.billerickson.net/code/rename-category-taxonomy/</link>
		
		<dc:creator><![CDATA[Bill Erickson]]></dc:creator>
		<pubDate>Mon, 25 May 2020 19:09:17 +0000</pubDate>
				<guid isPermaLink="false">https://www.billerickson.net/?post_type=code&#038;p=8341</guid>

					<description><![CDATA[<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/rename-category-taxonomy/">Rename category taxonomy</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-code"><code>/**
 * Rename Category to Theme
 *
 */
function be_rename_category_theme() {

	$singular_name = 'Theme';
	$plural_name = 'Themes';

	$labels = array(
		  'name'					=> $plural_name,
		  'menu_name'				=> $plural_name,
		  'singular_name'			=> $singular_name,
		  'search_items'			=> 'Search ' . $plural_name,
		  'popular_items'			=> 'Popular ' . $plural_name,
		  'all_items'				=> 'All ' . $plural_name,
		  'parent_item'				=> 'Parent ' . $singular_name,
		  'parent_item_colon'		=> 'Parent ' . $singular_name . ':',
		  'edit_item'				=> 'Edit ' . $singular_name,
		  'view_item'				=> 'View ' . $singular_name,
		  'update_item'				=> 'Update ' . $singular_name,
		  'add_new_item'			=> 'Add New ' . $singular_name,
		  'new_item_name'			=> 'New ' . $singular_name . ' Name',
		  'separate_items_with_commas' => 'Separate ' . $plural_name . ' with commas',
		  'add_or_remove_items'		=> 'Add or remove ' . $plural_name,
		  'back_to_items'			=> '&larr; Back to ' . $plural_name,
		  'items_list_navigation' 	=> $plural_name . ' list navigation',
		  'items_list'				=> $plural_name . ' list',
	  );

	  global $wp_taxonomies;
	  $wp_taxonomies['category']->labels = (object) array_merge( (array) $wp_taxonomies['category']->labels, $labels );
}
add_action( 'init', 'be_rename_category_theme' );</code></pre>
<p>The post <a rel="nofollow" href="https://www.billerickson.net/code/rename-category-taxonomy/">Rename category taxonomy</a> appeared first on <a rel="nofollow" href="https://www.billerickson.net">Bill Erickson</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
