Skip to content

Instantly share code, notes, and snippets.

View richerimage's full-sized avatar

Richard Barratt richerimage

View GitHub Profile
@djrmom
djrmom / facetwp-schedule-indexer.php
Last active January 26, 2021 16:56
facetwp schedule indexer
<?php
/*
Plugin Name: FacetWP Schedule Indexer
Plugin URI: https://facetwp.com/
Description: Runs indexer periodically by cron
Version: 1.0
Author: FacetWP, LLC
*/
add_action( 'fwp_scheduled_index', 'fwp_scheduled_index' );
@kingkool68
kingkool68 / use-remote-media.php
Last active March 24, 2024 11:37
Check if a local file exists in the WordPress media library and if it doesn't exist, replace the URL with a different URL. Helpful when working with a local site that doesn't have all of the media downloaded as the production site. See https://localwp.com/community/t/proxying-requests-to-wp-content-uploads-to-a-production-site/15701
<?php
// Put this in wp-config.php and replace https://example.com/ with the URL of the production site.
define( 'RH_USE_REMOTE_MEDIA_URL', 'https://example.com/' );
// Put the rest of this in functions.php or a custom plugin or somewhere else.
if ( defined( 'RH_USE_REMOTE_MEDIA_URL' ) && ! empty( RH_USE_REMOTE_MEDIA_URL ) ) {
add_filter( 'wp_get_attachment_image_src', 'filter_wp_get_attachment_image_src' );
add_filter( 'wp_calculate_image_srcset', 'filter_wp_calculate_image_srcset' );
add_filter( 'wp_get_attachment_url', 'filter_wp_get_attachment_url' );
}
@tomjn
tomjn / tomjn_http2_push.php
Created January 25, 2019 23:43
A naive and incomplete, but functional approach to http2 push
<?php
/**
* Plugin name: HTTP2 Push scripts
* Author: Tom J Nowell
*/
function tomjn_get_dep_url( /*\WP_Dependency*/ $dep ) {
global $wp_version;
$relative = str_replace( site_url(), '', $dep->src );
$ver = $dep->ver;
@kingkool68
kingkool68 / svg-functions.php
Created August 4, 2017 03:22
SVG helper functions for WordPress
<?php
// Throw this in your theme and include it in your functions.php file
/**
* Helper function for fetching SVG icons
*
* @param string $icon Name of the SVG file in the icons directory
* @return string Inline SVG markup
*/
function wp_svg_icon( $icon = '' ) {
@mgibbs189
mgibbs189 / custom-loop.php
Last active September 1, 2022 13:25 — forked from SauntValerian/gist:a79845e301de969017e714a96ffee6da
Multiple Loops for FacetWP
<?php
$args = array(
'post_type' => 'location',
'posts_per_page' => -1,
'order' => 'ASC',
'orderby' => 'title',
'facetwp' => true,
'tax_query' => array(
array(
'taxonomy' => 'advertiser-level',
@tanmay27vats
tanmay27vats / script.js
Last active January 5, 2024 22:58
Custom Add to cart WooCommerce, Refresh fragments data, Refresh cart total items, Get product variation
product_add_to_cart : function(){
var ajx_data = {};
var ajx_grab = {};
$(document).on('change','.single-product .variations_form select',function(e){
var $this = $(this);
var pro_id = $(".single-product .variations_form").attr('data-product_id');
var attribute_name = $this.attr('data-attribute_name');
var attribute_value = $this.val();
var post_ajxurl = window.location+"?wc-ajax=get_variation";
@kingkool68
kingkool68 / instagram-fetch.php
Last active April 8, 2023 22:43
A brief example of working with an external API in WordPress
<?php
// In this brief example we'll scrape an Instagram post and save it as a WordPress post
// Go to a URL and get the contents back
// See https://developer.wordpress.org/reference/functions/wp_remote_get/
$instagram_request = wp_remote_get( 'https://www.instagram.com/p/BSBvNVIF8tI/' );
// If it's succesful, the payload of the request will be in $instagram_request['body']
$instagram_html = $instagram_request['body'];
@kingkool68
kingkool68 / boagworld-lazy-load-images.php
Created March 21, 2017 15:58
Lazy Load Images WordPress Plugin for Boagworld
<?php
/*
Plugin Name: Bogworld's Special Neat-o Plugin
Description: See https://twitter.com/boagworld/status/844200551017562112
Author: kingkool68
Version: 0.0.1
Author URI: https://twitter.com/kingkool68
*/
/*
@isaumya
isaumya / back-button-refresh.php
Created December 23, 2016 12:05
Refresh page when click browser back button
<?php
/**
* Adding a special function to ensure that when the user click on back button,
* it will reload the pages, instead of loading from cache so that the js can run again
**/
add_action( 'wp_footer', 'aicp_refresh_on_back' );
function aicp_refresh_on_back() {
echo '<input type="hidden" id="refreshed" value="no">
<script type="text/javascript">
onload=function(){
@isaumya
isaumya / console-log-special-message.js
Created December 11, 2016 11:01
Showing special message in the console.log
/* This script will show a special designed message in the console.log section of your website
* for those who looks for something extra in your website.
* Fiddle Link: https://jsfiddle.net/isaumya/vtjswjuL/
**/
jQuery(function ($) {
try{
console.log("%c < ISAUMYA /> ","background: linear-gradient(to right, rgba(231,76,60,1) 0%,rgba(155,89,182,1) 100%););font-size:3em;border-radius:1em;color:#ffffff;font-weight:bold;font-style: italic;");
console.log('%c made with ♥ by Saumya Majumder © 2016', 'color: #e74c3c;font-size:1.1em;');
}
catch(e){}