Skip to content

Instantly share code, notes, and snippets.

View mattradford's full-sized avatar
👋

Matt Radford mattradford

👋
View GitHub Profile
@mattradford
mattradford / yoast_social_images.php
Created December 1, 2016 13:08
Force Yoast to use Featured Image large size instead of full for OpenGraph and Twitter images, to keep within their image size limits
// https://github.com/Yoast/wordpress-seo/issues/2921
function tend_custom_twitter_image_size( $img_size ) {
return 'large';
}
add_filter( 'wpseo_twitter_image_size', 'tend_custom_twitter_image_size');
add_filter( 'wpseo_opengraph_image_size', 'tend_custom_twitter_image_size' );
@mattradford
mattradford / hide_acf_sections.php
Created September 7, 2016 12:06
Hide ACF flexible content sections from users, rather than delete them
// This hides page builder sections from users
// First add class to the body based on template, then target those classes with deisplay: none
function acf_admin_head_layout() {
?>
<style type="text/css">
/* Remove borders on li since we not removing li's */
.acf-fc-popup li {
border:0 !important;
}
@mattradford
mattradford / product_category_template.php
Last active September 20, 2021 12:56
WooCommerce Product category (showing products) different template
function tend_product_listing( $original_template ) {
if ( is_tax( 'product_cat' ) ) {
$term = get_queried_object();
$children = get_terms( $term->taxonomy, array(
'parent' => $term->term_id,
'hide_empty' => false,
) );
if ( ! $children ) {
return wc_get_template_part( 'archive-product-listing' );
} else {
@mattradford
mattradford / gravity_spinner_css
Created June 17, 2016 13:54
Gravity Forms replacement spinner
.gform_ajax_spinner {
margin-left: 20px; /* give it some space from the Submit button */
border: 4px solid rgba(255, 255, 255, 0.3); /* match with border-left */
border-left: 4px solid gold;
animation: spinner 1.1s infinite linear;
border-radius: 50%;
width: 30px; /* match with height for a circle */
height: 30px;
}
@keyframes spinner {
@mattradford
mattradford / gravity_forms_filter_spinner.php
Created June 17, 2016 12:54
Filters the Gravity Forms spinner and replaces it with a base64-encoded blank image
function gf_spinner_replace( $image_src, $form ) {
return 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'; // relative to you theme images folder
}
add_filter( 'gform_ajax_spinner_url', 'gf_spinner_replace', 10, 2 );
@mattradford
mattradford / encoding fix.sql
Created June 15, 2016 15:40
WordPress Database encoding cleanup. YMMV.
UPDATE wp_posts SET post_content = REPLACE(post_content, '“', '“');
UPDATE wp_posts SET post_content = REPLACE(post_content, '”', '”');
UPDATE wp_posts SET post_content = REPLACE(post_content, '’', '’');
UPDATE wp_posts SET post_content = REPLACE(post_content, '‘', '‘');
UPDATE wp_posts SET post_content = REPLACE(post_content, '—', '–');
UPDATE wp_posts SET post_content = REPLACE(post_content, '–', '—');
UPDATE wp_posts SET post_content = REPLACE(post_content, '•', '-');
UPDATE wp_posts SET post_content = REPLACE(post_content, '…', '…');
UPDATE wp_posts SET post_title = REPLACE(post_title, '“', '“');
@mattradford
mattradford / svg_output.php
Created April 8, 2016 17:08
SVG output function
// Check and return an SVG icon inline
// Adapted from https://jdsteinbach.com/wordpress/using-svgs-wordpress/
// Needs SVG Support plugin as well
function tend_print_svg( $icon ) {
if ( false !== strpos( $icon, '.svg' ) ) {
$icon = str_replace( site_url(), '', $icon );
include( ABSPATH . $icon );
}
return $icon;
}
@mattradford
mattradford / menu_with_title.php
Last active January 23, 2018 12:49
Output menu with menu title
<?php
$menu = 'footer_primary_nav';
if (has_nav_menu($menu)) {
$locations = get_nav_menu_locations();
$menu_id = $locations[$menu] ;
$menu_object = wp_get_nav_menu_object($menu_id);
$menu_title = $menu_object->name;
// print_r($menu_object);
wp_nav_menu(array(
'theme_location' => $menu,
@mattradford
mattradford / rest_extended_cpt.php
Created November 19, 2015 12:59
Add REST visibility to CPT created with extended CPTS.
//http://wordpress.stackexchange.com/questions/201657/wp-rest-api-fetch-posts-from-post-type
add_action( 'init', 'add_adverts_to_json_api', 30 );
function add_adverts_to_json_api(){
global $wp_post_types;
$wp_post_types['advert']->show_in_rest = true;
}
@mattradford
mattradford / first_tax_term.php
Created November 15, 2015 15:49
Get first taxonomy term
$tax = 'property-type';
$tax_terms = wp_get_object_terms( $post->ID, $tax );
if (!empty( $tax_terms )) {
$term = array_pop($tax_terms);
_e('This is a ','turnerestates');
echo '<a href="' . get_term_link( $term->slug, $tax ) . '">' . strtolower($term->name) . '</a>';
_e(' property.','turnerestates');
}