Skip to content

Instantly share code, notes, and snippets.

Avatar

Addison Hall addisonhall

View GitHub Profile
@addisonhall
addisonhall / ACF_random_image.php
Last active Nov 22, 2021
ACF random image for GeneratePress background image URL
View ACF_random_image.php
<?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 Sep 6, 2021
Simple Wordpress shortcode to output current post title
View get_post_title_shortcode.php
/**
* 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 / gp-hide-paging-navigation.css
Last active Nov 12, 2020
Hide GeneratePress post navigation via CSS
View gp-hide-paging-navigation.css
.paging-navigation {
display: none;
}
@addisonhall
addisonhall / wp-site-tagline-shortcode.php
Last active Nov 10, 2020
Shortcode to output site tagline
View wp-site-tagline-shortcode.php
/**
* 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 Apr 23, 2020
Wordpress: Enqueue CSS for custom post type only
View function-enqueue-cpt-css.php
<?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 / wp_user_shortcodes.php
Created Oct 12, 2018
Handy user shortcodes for WordPress
View wp_user_shortcodes.php
/**
* 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;
}
/**
@addisonhall
addisonhall / wpsp_remove_permalinks.php
Last active Dec 2, 2017
Add this to WordPress functions.php to selectively disable permalinks on the WP Show Posts plugin. (https://wpshowposts.com/)
View wpsp_remove_permalinks.php
@addisonhall
addisonhall / content-cpt-output-list.php
Last active Nov 4, 2017
WordPress shortcode example: output custom post type list by custom taxonomy
View content-cpt-output-list.php
<?php
/**
* Partial for custom_post_type_list shortcode output.
*
* @package ChildTheme
*/
if ( ! defined( 'ABSPATH' ) ) exit; ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
@addisonhall
addisonhall / shortcodes-ultimate-columns-override.css
Created Sep 22, 2017
Mo' better responsive row and column styling for WP Shortcodes Ultimate
View shortcodes-ultimate-columns-override.css
/* Shortcodes Utlimate Rows and Columns */
.gpc .su-row {
margin: 0 -2% 1.5em -2%;
}
.gpc .su-row .su-column {
margin-left: 0;
margin-right: 0;
padding: 0 2% 0;
}
.gpc .su-column-size-1-1 { width: 100%; }
@addisonhall
addisonhall / web.config
Last active Nov 24, 2018
WordPress on IIS web.config with headers and cache control. Be sure to update "http://mydomain.com" with your site domain.
View web.config
<?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>