Skip to content

Instantly share code, notes, and snippets.

View thetwopct's full-sized avatar

James Hunt thetwopct

View GitHub Profile
@kierzniak
kierzniak / functions.php
Last active February 5, 2020 09:57
Function to resolve assets url with attached content hash
<?php
/**
* Function to resolve assets url with attached content hash.
*
* Browser cache mechanism is used to store locally once downloaded assets. This
* improves website performance and saves network bandwidth. It may be also creating
* a problem when a user visits your website and do not see the newest changes in assets
* because the browser is serving an old file from cache.
*
@nathanrice
nathanrice / modular-stylesheets.php
Last active April 11, 2020 14:36
A simple proof-of-concept for modularizing the CSS for each block, and linking it "just in time".
<?php
// this snippet requires PHP 5.3+
add_action( 'wp_enqueue_scripts', function() {
wp_register_style( 'atomic-blocks/ab-cta', '/path/to/atomic-blocks/css/ab-cta.css', array(), 1.0.0 );
} );
add_filter( 'render_block', function( $block_content, $block ) {
if ( 'atomic-blocks/ab-cta' === $block['blockName'] ) {
ob_start();
wp_print_styles( $block['blockName'] );
@mattiasghodsian
mattiasghodsian / index.php
Last active April 28, 2023 08:36
[PHP] List any users public gists
/**
* Title: Get gists
* Author: Mattias Ghodsian
* Description: List any users public gists
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5
*/
$profile_url = "https://api.github.com/users/mattiasghodsian/gists";
$options = array('http' => array('user_agent'=> $_SERVER['HTTP_USER_AGENT']));
@danyj
danyj / thz_disable_gutenberg.php
Created October 25, 2018 09:15
Disable Gutenberg globally or for specific post types for WordPress 5.0 and UP
<?php
/*
* Disable Gutenberg globally
* use this if you prefer one-liner
* add_filter('use_block_editor_for_post', '__return_false');
*/
function _thz_filter_disable_block_editor(){
return false;
}
add_filter( 'use_block_editor_for_post', '_thz_filter_disable_block_editor' );
<?php
namespace DeliciousBrains\Admin;
use DeliciousBrains\DBI;
class ACF {
public function init() {
add_filter( 'acf/settings/save_json', array( $this, 'get_local_json_path' ) );
@tylerlwsmith
tylerlwsmith / acf-google-maps.php
Created April 11, 2018 11:08
JavaScript-free implementation of Google Maps with WordPress Advanced Custom Fields
<?php
/**
* Set constants for Google Maps JS API key--used for ACF's backend map--and Google Maps
* Embed API Key, used for generating maps on the site front end.
*
* @link https://developers.google.com/maps/documentation/javascript/get-api-key
* @link https://developers.google.com/maps/documentation/embed/get-api-key
*/
const GOOGLE_MAPS_JS_API_KEY = 'MAPS-JS-API-KEY';
@ecrider
ecrider / php_curl_download_repos.php
Last active March 18, 2024 03:45
Download repos with PHP and cURL from GitHub API as zip/tarball
<?php
/**
* Wasted half my evening trying to get this done.
* Those seems to be the only settings that works for
* downloading large repositories as zip/tarball
* from GitHub with PHP and cURL.
*
* If you don't have to use PHP, then use cURL direcly:
* curl -L -v -H "Authorization: token PERSONAL_ACCESS_TOKEN" https://api.github.com/repos/SOME_USER/SOME_REPO/zipball > dooone.zip
*/
@ControlledChaos
ControlledChaos / README.md
Last active March 7, 2024 04:41
Add srcset and sizes attributes to Advanced Custom Fields image uploads.

ACF Responsive Images

WordPress Snippet

Adds the srcset and sizes attributes to ACF image uploads. Requires installation of the Advanced Custom Fields plugin.

NOTE: ACF image field must be set to return the ID.

NOTE: WordPress needs image sizes with equal aspect ratios in order to generate the srcset, and does not use srcset when images are added as "Full Size".

@jawinn
jawinn / primary_category.php
Last active December 8, 2022 21:42
Display Primary Category (Yoast's WordPress SEO)
<?php
/**
* Get the Yoast primary category from its post meta value, and displays it, with HTML markup.
* If there is no primary category set, it displays the first assigned category.
*
* @param boolean $useCatLink Whether to link the category, if it exists
* @return void
*/
function yourtheme_display_yoast_primary_category( $useCatLink = true ) {
@joshuadavidnelson
joshuadavidnelson / example-output.html
Last active January 22, 2024 12:42
Using WordPress responsive images for css background-image property, in-line styling
<style>
.header {
background-image: url(http://local.dev/wp-content/uploads/2016/04/image-300x151.png)
}
@media only screen and (min-width: 300px) {.header {
background-image: url(http://local.dev/wp-content/uploads/2016/04/image-768x386.png)
}}
@media only screen and (min-width: 768px) {.header {
background-image: url(http://local.dev/wp-content/uploads/2016/04/image-1024x515.png)
}}