Skip to content

Instantly share code, notes, and snippets.

@bewho
bewho / wp-functions.php
Created December 19, 2018 12:34 — forked from mohsinr/wp-functions.php
WordPress Common Custom Codes for Functions.php
<?php
//* Add new image sizes
add_image_size( 'logo-thumb', 270, 180, TRUE );
//* Change the number of portfolio items to be displayed (props Bill Erickson)
add_action( 'pre_get_posts', 'minimum_portfolio_items' );
function minimum_portfolio_items( $query ) {
if ( $query->is_main_query() && !is_admin() && is_post_type_archive( 'portfolio' ) ) {
$query->set( 'posts_per_page', '6' );
@bewho
bewho / create_deferred_image_tag.php
Created December 19, 2018 03:38 — forked from bpb54321/create_deferred_image_tag.php
Outputs HTML for image tags that load a WordPress medium size image on initial load, then a separte javascript file (image_deferred.js) loads in the srcset and sizes attributes.
/**
* Helper function for getting the widths and url's of all the available crops of an image.
* @param Number $id : The id of the image that you need the info for
* @param Array $image_sizes_to_exclude An array of strings with the names of image sizes to exclude from the output
* @return Array An indexed array, where at each index there is an associative array with array["width"] containing an image width and array["url"] containing the corresponding image url.
* Example: Array(
* [0] => Array(
* [width] => 300
* [url] => http://placehold.it/50x50
* ),
@bewho
bewho / SEO Checklist.md
Created December 18, 2018 10:12 — forked from ericrasch/SEO Checklist.md
SEO Checklist
@bewho
bewho / disable_self_ping.php
Created October 10, 2018 01:50 — forked from glueckpress/disable_self_ping.php
Disable self trackbacks from your own WordPress blog.
<?php
// Retrieved from: http://wp-snippets.com/disable-self-trackbacks/
add_action( 'pre_ping', 'disable_self_ping' );
function disable_self_ping( &$links ) {
foreach ( $links as $l => $link )
if ( 0 === strpos( $link, get_option( 'home' ) ) )
unset($links[$l]);
}
@bewho
bewho / wp-rocket-exclude-from-defer-only.php
Created October 10, 2018 01:43 — forked from glueckpress/wp-rocket-exclude-from-defer-only.php
[WordPress][WP Rocket] Barely tested hack to exclude a file from defer JS only, without having to exclude it from minification.
<?php
/**
* WP Rocket:
* 1. Customise order of minification and defer operations.
* 2. Exclude file from defer JS only (still minified).
*
* Tested rudimentary with WP Rocket 2.11.7 and 3.0.x.
* Test before using this in production!
*/
add_action( 'wp_rocket_loaded', function () {
@bewho
bewho / wp-rocket-unlazyload-essential-grid.php
Created October 10, 2018 01:42 — forked from glueckpress/wp-rocket-unlazyload-essential-grid.php
[WordPress][WP Rocket] Programmatically disables WP Rocket’s LazyLoad feature on pages with Essential Grid.
<?php
/**
* Plugin Name: WP Rocket | UnLazyLoad Essential Grid
* Description: Disables WP Rocket’s LazyLoad feature on pages with <a href="https://www.themepunch.com/portfolio/essential-grid-wordpress-plugin/">Essential Grid</a>.
* Author: WP Rocket Support Team
* Author URI: http://wp-rocket.me/
* Plugin URI: http://docs.wp-rocket.me/article/139-disable-lazyload-on-mobile#inactive
* License: GNU General Public License v3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
@bewho
bewho / wp-config.php
Created October 10, 2018 01:41 — forked from voneff/wp-config.php
WordPress: custom security measures for wp-config.php
# Custom Security Measures by @voneff
#
# Sources:
# @link https://gist.github.com/voneff/f66128aaacd350294e8a
# @link https://premium.wpmudev.org/blog/keeping-wordpress-secure-the-ultimate-guide
# @link https://kinsta.com/blog/wp-config-php/
# @link https://kittpress.com/wordpress-sicherheit-2-erste-konfiguration/
#
# Turn Off PHP Error Reporting:
@bewho
bewho / functions.php
Created October 10, 2018 01:41 — forked from voneff/functions.php
WordPress: security measures for functions.php
<?php
/*
* Disable version information from being displayed in the header or RSS feed
*
* Sources:
* http://torquemag.io/2016/06/keep-your-wordpress-site-safe-with-these-four-tips/
*/
function disable_version_info() {
@bewho
bewho / functions.php
Created October 10, 2018 01:40 — forked from voneff/functions.php
WordPress: disabling Emojis and keeping emoticons as text
<?php
/**
* Disable WordPress emojis
* Source: https://kinsta.com/knowledgebase/disable-emojis-wordpress/#disable-emojis-code
*/
function disable_emojis() {
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' );
@bewho
bewho / functions.php
Created October 10, 2018 01:40 — forked from voneff/functions.php
WordPress: Disable IP collection through WordPress comments
<?php
/**
* Remove IP collection in WordPress comments
* Source: http://www.wpbeginner.com/wp-tutorials/how-to-stop-storing-ip-address-in-wordpress-comments/
*/
function wpb_remove_commentsip( $comment_author_ip ) {
return '';
}
add_filter( 'pre_comment_user_ip', 'wpb_remove_commentsip' );