Skip to content

Instantly share code, notes, and snippets.

View thetwopct's full-sized avatar

James Hunt thetwopct

View GitHub Profile
@don1138
don1138 / font-stacks.css
Last active May 14, 2024 13:16
CSS Modern Font Stacks
/* Modern Font Stacks */
/* System */
font-family: system, -apple-system, ".SFNSText-Regular", "San Francisco", "Roboto", "Segoe UI", "Helvetica Neue", "Lucida Grande", sans-serif;
/* System (Bootstrap 5.2.0) */
font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "Liberation Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
/* Times New Roman-based serif */
font-family: Cambria, "Hoefler Text", Utopia, "Liberation Serif", "Nimbus Roman No9 L Regular", Times, "Times New Roman", serif;
@eltonmesquita
eltonmesquita / onViewport.js
Last active November 1, 2020 09:32
A simple jQuery function that adds a class when the target(s) is in the viewport
function onViewport(el, elClass, offset, callback) {
/*** Based on http://ejohn.org/blog/learning-from-twitter/ ***/
var didScroll = false;
var this_top;
var height;
var top;
if(!offset) { var offset = 0; }
$(window).scroll(function() {
@nmyers
nmyers / acf-map.php
Last active February 19, 2020 06:56
ACF Static google map with link #acf #wp
<?php
$location = get_field('location');
if( !empty($location) ):
?>
<a href="http://www.google.com/maps/preview#!q=<?=urlencode( $location['address'] )?>">
<img src="http://maps.googleapis.com/maps/api/staticmap?center=<?php echo $location['lat']; ?>,<?php echo $location['lng']; ?>&zoom=15&format=png&sensor=false&size=397x297&maptype=roadmap&visual_refresh=true&style=visibility:off&style=feature:road|element:geometry|visibility:simplified&style=feature:landscape|element:geometry|visibility:simplified&style=element:labels|visibility:on&markers=color:red|<?php echo $location['lat']; ?>,<?php echo $location['lng']; ?>"/>
</a>
<?php endif; ?>
@mohandere
mohandere / yoast-seo-sitemap.php
Last active February 4, 2024 04:58
Wordpress yoast seo plugin, generate custom sitemap for custom URLS
<?php
/**
* Create a new custom yoast seo sitemap
*/
add_filter( 'wpseo_sitemap_index', 'ex_add_sitemap_custom_items' );
add_action( 'init', 'init_wpseo_do_sitemap_actions' );
// Add custom index
@mgburns
mgburns / acf-field-registration-example.php
Created September 1, 2015 13:14
Example programmatic registration of Advanced Custom Fields fields
<?php
/**
* Example programmatic registration of Advanced Custom Fields fields
*
* @see http://www.advancedcustomfields.com/resources/register-fields-via-php/
*/
function register_custom_acf_fields() {
if ( function_exists( 'acf_add_local_field_group' ) ) {
@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)
}}
@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 ) {
@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".

@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
*/
@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';