Delay Posts in RSS Feeds

Add a delay before published posts show up in the RSS feeds.

Use Snippet
php
<?php
function wpcode_snippet_publish_later_on_feed( $where ) {
	global $wpdb;
	if ( is_feed() ) {
		// Timestamp in WP-format.
		$now = gmdate( 'Y-m-d H:i:s' );
		// Number of unit to wait
		$wait = '10'; // integer.
		// Choose time unit.
		$unit = 'MINUTE'; // MINUTE, HOUR, DAY, WEEK, MONTH, YEAR.
		// Add SQL-sytax to default $where. By default 10 minutes.
		$where .= " AND TIMESTAMPDIFF($unit, $wpdb->posts.post_date_gmt, '$now') > $wait ";
	}
	return $where;
}
add_filter( 'posts_where', 'wpcode_snippet_publish_later_on_feed' );
WPCode Team
80+

Set oEmbed Max Width

Set a max width for the embeds using oEmbed in the content.

Use Snippet
php
<?php
function wpcode_snippet_oembed_defaults( $sizes ) {
	return array(
		'width'  => 400,
		'height' => 280,
	);
}
add_filter( 'embed_defaults', 'wpcode_snippet_oembed_defaults' );
WPCode Team
60+

Postalytics Tracking Script

Mail tracker

Use Snippet
js
<script type="text/javascript">    
    var a;
var rc = new RegExp('_bn_d=([^;]+)');
var rq = new RegExp('_bn_d=([^&#]*)', 'i');
var aq = rq.exec(window.location.href);
if (aq != null) a=aq;
else var ac = rc.exec(document.cookie);
if (ac != null) a=ac;
if (a != null) {
  var _bn_d = a[1];  
  (function() {
	var pl = document.createElement('script'); pl.type = 'text/javascript'; pl.async = true;
	pl.src = ('https:' == document.location.protocol ? 'https://app' : 'http://app') + '.postaladmin.com/plDataEmbed.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(pl, s);
  })();
}
    </script>
Mark Cornish
<10

Disable Comment Form Website URL

Remove the Website URL field from the Comments form.

Use Snippet
php
<?php
add_filter( 'comment_form_default_fields', function ($fields) {
	if ( isset( $fields['url'] ) ) {
		unset( $fields['url'] );
	}
	return $fields;
}, 150 );
WPCode Team
<10

Disable Emojis

Disable Emoji's in WordPress to improve your site's performance

Use Snippet
php
<?php
/**
 * Disable the emojis in WordPress.
 */
add_action( 'init', function () {
	remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
	remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
	remove_action( 'wp_print_styles', 'print_emoji_styles' );
	remove_action( 'admin_print_styles', 'print_emoji_styles' );
	remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
	remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
	remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
	// Remove from TinyMCE.
	add_filter( 'tiny_mce_plugins', function ( $plugins ) {
		if ( is_array( $plugins ) ) {
			return array_diff( $plugins, array( 'wpemoji' ) );
		} else {
			return array();
		}
	} );
	// Remove from dns-prefetch.
	add_filter( 'wp_resource_hints', function ( $urls, $relation_type ) {
		if ( 'dns-prefetch' === $relation_type ) {
			$emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/' );
			$urls          = array_diff( $urls, array( $emoji_svg_url ) );
		}
		return $urls;
	}, 10, 2 );
} );
WPCode Team
<10

Remove Login Shake Animation

Prevent the Login box from shaking when entering the wrong password or username.

Use Snippet
php
<?php
add_action( 'login_footer', function () {
	remove_action( 'login_footer', 'wp_shake_js', 12 );
} );
WPCode Team
<10

Disable Embeds

Remove an extra request and prevent others from adding embeds in your site.

Use Snippet
php
<?php
/**
 * Disable all embeds in WordPress.
 */
add_action( 'init', function () {
	// Remove the REST API endpoint.
	remove_action( 'rest_api_init', 'wp_oembed_register_route' );
	// Turn off oEmbed auto discovery.
	add_filter( 'embed_oembed_discover', '__return_false' );
	// Don't filter oEmbed results.
	remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );
	// Remove oEmbed discovery links.
	remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
	// Remove oEmbed-specific JavaScript from the front-end and back-end.
	remove_action( 'wp_head', 'wp_oembed_add_host_js' );
	add_filter( 'tiny_mce_plugins', function ( $plugins ) {
		return array_diff( $plugins, array( 'wpembed' ) );
	} );
	// Remove all embeds rewrite rules.
	add_filter( 'rewrite_rules_array', function ( $rules ) {
		foreach ( $rules as $rule => $rewrite ) {
			if ( false !== strpos( $rewrite, 'embed=true' ) ) {
				unset( $rules[ $rule ] );
			}
		}
		return $rules;
	} );
	// Remove filter of the oEmbed result before any HTTP requests are made.
	remove_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10 );
}, 9999 );
WPCode Team
<10

Rael Facial Wipes Banner

Use Snippet
html
<a href="https://giftly.klickly.com/reward/dfe988ed-5b05-43f0-bd6d-6a5c6e5225f9?utm_source=btv&utm_medium=stream&utm_campaign=stream_btvextcmpn_giftly&infl=XXX”
target="_blank"><img src="https://assets.unlayer.com/stock-templates1668804827173-Rael_Facial_Banner.png”></a>
Brian Martin
<10

Add default ALT to avatar/Gravatar Images

Add the user's name as a default alt tag to the Gravatar images loaded on...

Use Snippet
php
<?php
add_filter(
	'pre_get_avatar_data',
	function ( $atts ) {
		if ( empty( $atts['alt'] ) ) {
			if ( have_comments() ) {
				$author = get_comment_author();
			} else {
				$author = get_the_author_meta( 'display_name' );
			}
			$alt = sprintf( 'Avatar for %s', $author );
			$atts['alt'] = $alt;
		}
		return $atts;
	}
);
WPCode Team
<10

WooCommerce number of archive products per page

Change WooCommerce Archive products number per page code snippet.

Use Snippet
php
<?php
/*  Change WooCommerce Archive products number per page */
 
add_filter( 'loop_shop_per_page', 'my_new_products_per_page', 9999 );
 
function my_new_products_per_page( $pr_per_page ) {
  $pr_per_page = 16;
  return $pr_per_page;
}
Tahbit Al Bashar
<10

Remove Query Strings From Static Files

Use this snippet to remove query string from CSS & JS files and improve performance...

Use Snippet
php
<?php
function wpcode_snippet_remove_query_strings_split( $src ) {
	$output = preg_split( "/(&ver|?ver)/", $src );
	return $output ? $output[0] : '';
}
add_action( 'init', function () {
	if ( ! is_admin() ) {
		add_filter( 'script_loader_src', 'wpcode_snippet_remove_query_strings_split', 15 );
		add_filter( 'style_loader_src', 'wpcode_snippet_remove_query_strings_split', 15 );
	}
} );
WPCode Team
<10

Tyler Hall Tech Custom Snippets

All the Goodies

Use Snippet
php
<?php
// Custom PHP Code by Tyler (TITLE)
	function page_title_sc( ){
   return get_the_title();
}
add_shortcode( 'page_title', 'page_title_sc' );
// Enable Shortcode Execution in Text Widgets
add_filter( 'widget_text', 'do_shortcode' );
// Disable Gutenberg Editor (use Classic Editor)
add_filter('gutenberg_can_edit_post', '__return_false', 5);
add_filter('use_block_editor_for_post', '__return_false', 5);
// Disable Widget Blocks
add_filter( 'use_widgets_block_editor', '__return_false' );
// Disable Automatic Updates
// Disable core auto-updates
add_filter( 'auto_update_core', '__return_false' );
// Disable auto-updates for plugins.
add_filter( 'auto_update_plugin', '__return_false' );
// Disable auto-updates for themes.
add_filter( 'auto_update_theme', '__return_false' );
// Allow SVG Files Upload
// /**
 * Allow SVG uploads for administrator users.
 *
 * @param array $upload_mimes Allowed mime types.
 *
 * @return mixed
 */
add_filter(
	'upload_mimes',
	function ( $upload_mimes ) {
		// By default, only administrator users are allowed to add SVGs.
		// To enable more user types edit or comment the lines below but beware of
		// the security risks if you allow any user to upload SVG files.
		if ( ! current_user_can( 'administrator' ) ) {
			return $upload_mimes;
		}
		$upload_mimes['svg']  = 'image/svg+xml';
		$upload_mimes['svgz'] = 'image/svg+xml';
		return $upload_mimes;
	}
);
/**
 * Add SVG files mime check.
 *
 * @param array        $wp_check_filetype_and_ext Values for the extension, mime type, and corrected filename.
 * @param string       $file Full path to the file.
 * @param string       $filename The name of the file (may differ from $file due to $file being in a tmp directory).
 * @param string[]     $mimes Array of mime types keyed by their file extension regex.
 * @param string|false $real_mime The actual mime type or false if the type cannot be determined.
 */
add_filter(
	'wp_check_filetype_and_ext',
	function ( $wp_check_filetype_and_ext, $file, $filename, $mimes, $real_mime ) {
		if ( ! $wp_check_filetype_and_ext['type'] ) {
			$check_filetype  = wp_check_filetype( $filename, $mimes );
			$ext             = $check_filetype['ext'];
			$type            = $check_filetype['type'];
			$proper_filename = $filename;
			if ( $type && 0 === strpos( $type, 'image/' ) && 'svg' !== $ext ) {
				$ext  = false;
				$type = false;
			}
			$wp_check_filetype_and_ext = compact( 'ext', 'type', 'proper_filename' );
		}
		return $wp_check_filetype_and_ext;
	},
	10,
	5
);
// Display the current year
// function year_shortcode () {
$year = date_i18n ('Y');
return $year;
}
add_shortcode ('year', 'year_shortcode');
Tyler Hall
<10

Disable wlwmanifest link

Prevent WordPress from adding the Windows Live Writer manifest link to your pages.

Use Snippet
php
<?php
remove_action('wp_head', 'wlwmanifest_link');
WPCode Team
<10

vohungy.com.vn

Use Snippet
html
Võ Hưng Ý
<10

Disable Self Pingbacks

Prevent WordPress from automatically creating pingbacks from your own site.

Use Snippet
php
<?php
add_action( 'pre_ping', function( &$links ) {
	$home = get_option( 'home' );
	foreach ( $links as $l => $link ) {
		if ( 0 === strpos( $link, $home ) ) {
			unset( $links[ $l ] );
		}
	}
} );
WPCode Team
<10
1 2 3 4