Skip to content

Instantly share code, notes, and snippets.

View addisonhall's full-sized avatar

Addison Hall addisonhall

View GitHub Profile
@addisonhall
addisonhall / Page-before-body-closing.html
Last active October 10, 2023 22:07
Webflow Hero Slider using Swiper JS
<script>
/**
* Activate swiper.js for testimonials
*/
doHeroSlider();
function doHeroSlider() {
// get hero slider element
const heroSlider = document.getElementById('heroSlider');
// shut it down if slider isn't present
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
@addisonhall
addisonhall / ACF_random_image.php
Last active November 22, 2021 21:22
ACF random image for GeneratePress background image URL
<?php
add_filter( 'generate_page_hero_background_image_url', function( $url ) {
$headers = array(
esc_url(get_field('radnomizer_image_one')),
esc_url(get_field('radnomizer_image_two')),
esc_url(get_field('radnomizer_image_three')),
esc_url(get_field('radnomizer_image_four')),
esc_url(get_field('radnomizer_image_five'))
);
@addisonhall
addisonhall / get_post_title_shortcode.php
Created September 6, 2021 18:05
Simple Wordpress shortcode to output current post title
/**
* Output the post title.
* [gpc_post_title]
*/
add_shortcode( 'gpc_post_title', 'gpc_post_title_func' );
function gpc_post_title_func() {
return get_the_title();
}
@addisonhall
addisonhall / wp_query-orderby-meta-1.php
Last active June 29, 2021 17:58
WP_Query: Orderby custom fields
<?php
$args = array(
'post_type' => 'custom_post_name' // including the post type name seems to make this not work!
'meta_key' => 'custom_field_name',
'orderby' => 'meta_value',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'custom_tax_name',
@addisonhall
addisonhall / gp-hide-paging-navigation.css
Last active November 12, 2020 19:23
Hide GeneratePress post navigation via CSS
.paging-navigation {
display: none;
}
@addisonhall
addisonhall / wp-site-tagline-shortcode.php
Last active November 10, 2020 14:42
Shortcode to output site tagline
/**
* Output site tagline.
* [gp_site_tagline]
*/
function gp_output_site_tagline_func() {
return get_bloginfo( 'description' );
}
add_shortcode( 'gp_site_tagline', 'gp_output_site_tagline_func' );
@addisonhall
addisonhall / function-enqueue-cpt-css.php
Last active April 23, 2020 16:06
Wordpress: Enqueue CSS for custom post type only
<?php
/**
* Enqueue specific CSS styles or javascript for a custom post type (cpt).
*/
add_action( 'wp_enqueue_scripts', 'my_cpt_scripts' );
function my_cpt_scripts() {
if ( is_singular( 'custom_post_type_name' ) || is_post_type_archive( 'custom_post_type_name' ) ) {
wp_enqueue_style( 'cpt-style', get_stylesheet_directory_uri() . '/css/your-cpt-style.css', false, '', 'all');
}
@addisonhall
addisonhall / web.config
Last active November 24, 2018 21:45
WordPress on IIS web.config with headers and cache control. Be sure to update "http://mydomain.com" with your site domain.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="Vary"></remove>
<add name="Vary" value="Accept-Encoding"></add>
</customHeaders>
</httpProtocol>
<staticContent>
@addisonhall
addisonhall / wp_user_shortcodes.php
Created October 12, 2018 19:21
Handy user shortcodes for WordPress
/**
* Add current user shortcode
*/
add_shortcode( 'current-user' , 'gpc_get_current_user' );
function gpc_get_current_user() {
$user = wp_get_current_user();
return $user->display_name;
}
/**