Skip to content

Instantly share code, notes, and snippets.

@npofopr
npofopr / DNS prefetching preconnect
Last active January 16, 2025 17:04
Common Prefetch Links
<!-- DNS preconnect -->
<meta http-equiv="x-dns-prefetch-control" content="on">
<link rel="preconnect" href="//ajax.googleapis.com">
<link rel="dns-prefetch" href="https://fonts.gstatic.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="anonymous">
<link rel="dns-prefetch" href="https://use.fontawesome.com">
<link rel="preconnect" href="https://use.fontawesome.com" crossorigin>
<link rel="preconnect" href="//cdnjs.cloudflare.com">
<link rel="preconnect" href="//www.googletagmanager.com">
<link rel="preconnect" href="//www.google-analytics.com">
@wplit
wplit / snippet.php
Created September 10, 2018 23:17
Remove Google Fonts from Oxygen Builder
// Remove Google Fonts from Oxygen
remove_action('wp_head', 'add_web_font',0);
@offroadkev
offroadkev / functions.php
Created July 20, 2018 22:05
Change Gravity Forms Spinner to CSS Spinner
// Changes Gravity Forms Ajax Spinner (next, back, submit) to a transparent image
// this allows you to target the css and create a pure css spinner like the one used below in the style.css file of this gist.
add_filter( 'gform_ajax_spinner_url', 'spinner_url', 10, 2 );
function spinner_url( $image_src, $form ) {
return 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'; // relative to you theme images folder
}
@teolaz
teolaz / ACFToArray.php
Last active July 24, 2024 18:13
This class is an helpful method to add a caching layer to Advanced Custom Fields. This works adding a new row on database with the entire ACF data serialized for that saved post or option page, and then WITH A SINGLE QUERY done you can have all data back and ready to use.
<?php
/**
* Created by PhpStorm.
* User: Matteo
* Date: 04/07/2018
* Time: 12:52
*/
/**
* Class ACFToArray
@jsn789
jsn789 / add-gtm-wp.php
Last active September 4, 2024 13:38
Add Google Tag Manager through functions.php in WordPress
/* Add Google Tag Manager javascript code as close to
the opening <head> tag as possible
=====================================================*/
function add_gtm_head(){
?>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
@anwas
anwas / wp-config.php
Last active November 10, 2021 11:35
[WordPress wp-config customization]
<?php
/* WordPress debug mode for developers. */
define( 'WP_DEBUG', true );
// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );
// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@kierzniak
kierzniak / functions.php
Created January 17, 2018 21:55
Search across all network blogs in elasticpress
<?php
/**
* Search across all network blogs with elasticpress
*
* @param $scope string Search scope
*
* @return string
*/
function motivast_ep_search_scope( $scope ) {
@Niq1982
Niq1982 / wpcli-ai1wm.md
Last active February 25, 2025 15:29
Site migration using All in One WP Migration and WP CLI

Do a backup

Install the plugin

wp plugin install all-in-one-wp-migration --activate

You must reload the page once before continuing

Do the backup

@devinsays
devinsays / estimate-read-time.php
Last active February 11, 2023 20:57
WordPress Estimated Read Time
<?php
/**
* Estimates the reading time for a given piece of $content.
*
* @param string $content Content to calculate read time for.
* @param int $wpm Estimated words per minute of reader.
*
* @returns int $time Esimated reading time.
*/
function prefix_estimated_reading_time( $content = '', $wpm = 300 ) {
@PauliusKrutkis
PauliusKrutkis / set-image.php
Created July 6, 2017 13:35
Wordpress set post thumbnail with media_sideload_image function
<?php
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');
$url = 'http://wordpress.org/about/images/logos/wordpress-logo-stacked-rgb.png';
$title = "Anything you want";
$postId = 1;