Skip to content

Instantly share code, notes, and snippets.

View mattradford's full-sized avatar
👋

Matt Radford mattradford

👋
View GitHub Profile
@mattradford
mattradford / gallery_post_thumbnail.php
Last active March 27, 2025 18:15
Set post thumbnail from gallery. Saves a performance hit.
function set_featured_image_from_gallery() {
$has_thumbnail = get_the_post_thumbnail($post->ID);
if ( !$has_thumbnail ) {
$images = get_field('gallery', false, false);
$image_id = $images[0];
if ( $image_id ) {
set_post_thumbnail( $post->ID, $image_id );
@mattradford
mattradford / acf_image_array.php
Created August 27, 2015 12:21
ACF - display image and alt text
(1)
<?php
$imageArray = get_field('footer_logo', 'options');
$imageAlt = $imageArray['alt'];
$imageURL = $imageArray['sizes']['thumbnail'];
?>
<img src="<?php echo $imageURL;?>" alt="<?php echo $imageAlt; ?>">
(2)
<?php
@mattradford
mattradford / acf_image_array.php
Created August 27, 2015 12:20
ACF - display image and alt text
(1)
<?php
$imageArray = get_field('footer_logo', 'options');
$imageAlt = $imageArray['alt'];
$imageURL = $imageArray['sizes']['thumbnail'];
?>
<img src="<?php echo $imageURL;?>" alt="<?php echo $imageAlt; ?>">
(2)
<?php
@mattradford
mattradford / tax_title.php
Created August 26, 2015 13:20
Return taxonomy title. For lib/titles.php
} elseif (is_tax('flooring-type')) {
$queried_object = get_queried_object();
return $queried_object->name;
@mattradford
mattradford / pseudo_bbg_transition.less
Created August 24, 2015 10:27
Transition on a psuedo element background
article {
.featured-image {
position: relative;
&:before {
.transition(all 0.3s ease);
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
@mattradford
mattradford / button_shortcode.php
Created August 21, 2015 12:13
Simple button shortcode
function tend_button( $atts, $content = null ) {
extract(shortcode_atts(array(
'link' => '#',
'class' => 'turq',
), $atts));
$out = '<a class="button ' .$class. '" href="' .$link. '">' .do_shortcode($content). '</a>';
return $out;
}
@mattradford
mattradford / show_registered_widgets.php
Created August 19, 2015 15:29
Show all registered widgets in wp-admin
function show_widget_classes() {
global $wp_registered_widgets;
$widgets = array();
if(is_array($wp_registered_widgets)){
foreach($wp_registered_widgets as $widg){
if(!empty($widg['callback'])){
if(!empty($widg['callback'][0])){
$class = get_class($widg['callback'][0]);
if(!array_key_exists($class, $widgets)){
$widgets[$class] = $widg['callback'][0]->name;
@mattradford
mattradford / unregister_widgets.php
Last active January 23, 2018 12:51
Unregister default and plugin widgets
function unregister_default_wp_widgets() {
unregister_widget('WP_Widget_Pages');
unregister_widget('WP_Widget_Calendar');
unregister_widget('WP_Widget_Archives');
unregister_widget('WP_Widget_Links');
unregister_widget('WP_Widget_Meta');
unregister_widget('WP_Widget_Categories');
unregister_widget('WP_Widget_Recent_Comments');
unregister_widget('WP_Widget_Tag_Cloud');
unregister_widget('WP_Widget_RSS');
@mattradford
mattradford / tax_terms_subnav.php
Created August 19, 2015 08:55
Tax terms subnav
<nav class="subnav">
<?php
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
$args = array(
'hide_empty' => false,
'orderby' => 'slug'
);
@mattradford
mattradford / related posts.php
Created August 18, 2015 12:28
Related posts usng ACF post object