Skip to content

Instantly share code, notes, and snippets.

View morgyface's full-sized avatar

Dan morgyface

View GitHub Profile
@morgyface
morgyface / acf_repeater_flexible.php
Created August 6, 2016 18:08
WordPress | ACF | Adaptive Repeater
<style>
ul {margin:0; padding:0; list-style:none; overflow:auto}
ul li {float:left}
ul.half li {width:50%}
ul.thirds li {width:calc(100% / 3); width:33.33%}
ul.quarters li {width:25%}
</style>
<?php
if( have_rows('repeater_field_name') ):
$repeater = get_field('repeater_field_name');
@morgyface
morgyface / acf_image_array.php
Created August 7, 2016 07:20
WordPress | ACF Image Array
<?php
$image = get_field('image');
if( !empty($image) ):
$url = $image['url'];
$thumb = $image['sizes'][ 'thumbnail' ];
echo '<img src="' . $url . '">'; // full size image
echo '<img src="' . $thumb . '">'; // thumbnail image
endif;
?>
@morgyface
morgyface / add-custom-post-type.php
Last active January 22, 2019 17:53
WordPress | Add a custom post type
<?php
// Add the custom post type
function create_post_type() {
register_post_type( 'kit-lists',
array(
'labels' => array(
'name' => __( 'Kit Lists' ),
'singular_name' => __( 'Kit List' )
),
'public' => true,
@morgyface
morgyface / favicon.php
Last active May 14, 2020 11:48
WordPress | Generate a universal favicon list
<link rel="shortcut icon" href="<?php bloginfo( 'template_directory' ); ?>/favicon/favicon.ico" />
<link rel="apple-touch-icon" sizes="152x152" href="<?php bloginfo( 'template_directory' ); ?>/favicon/favicon-152.png" />
<link rel="apple-touch-icon" sizes="180x180" href="<?php bloginfo( 'template_directory' ); ?>/favicon/favicon-180.png">
<link rel="apple-touch-icon" sizes="167x167" href="<?php bloginfo( 'template_directory' ); ?>/favicon/favicon-167.png">
<meta name="msapplication-TileColor" content="#000000">
<meta name="msapplication-TileImage" content="<?php bloginfo( 'template_directory' ); ?>/favicon/favicon-144.png">
@morgyface
morgyface / acf_image_background.php
Created January 2, 2017 16:24
WordPress | Using the ACF Image field to apply a background
<style>
div.panel {width:100%; height:100vh; background-position:center center; background-repeat:no-repeat; -webkit-background-size:cover; -moz-background-size:cover; -o-background-size:cover; background-size:cover}
</style>
<?php
// Image field with a return value of Image Array
$background_image = get_field('background_image');
echo '<div class="panel"';
if ( $background_image ) {
$size = 'large';
@morgyface
morgyface / loop_order_change.php
Last active January 7, 2017 16:53
WordPress | Loop | Order | pre_get_posts
<?php
// This alters the main loop (loop.php) to order Archive queries by Title
function archive_posts($query) {
if ( $query->is_archive() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'asc' );
}
}
add_action('pre_get_posts', 'archive_posts');
?>
@morgyface
morgyface / social-share.php
Last active September 26, 2018 15:54
WordPress | Social Share Buttons
<style>
div.social-share {position:absolute; bottom:0; right:0; text-align:center}
div.social-share h5 {font-size:0.875em; color:#333; text-transform:uppercase; margin:0}
div.social-share ul {padding:0; margin:0; list-style:none; font-size:2em}
div.social-share ul li {display:inline-block; margin-right:0.375em}
div.social-share ul li:last-child {margin:0}
div.social-share ul li a span {display:none}
div.social-share ul li a {text-decoration:none}
/* Change links to official colours */
div.social-share ul li.facebook a {color:#3b5998}
@morgyface
morgyface / wp-next-prev.php
Created February 10, 2017 15:41
WordPress | Next / Previous Post Links | Traversing posts
<style>
div.traverse {width: 100%; clear: both}
div.traverse a {display: block; width: 50%}
div.traverse a.prev {float: left}
div.traverse a.next {float: right; text-align: right}
</style>
<?php
// The traverse navigation to adjacent posts
$prev_post = get_adjacent_post(false, '', true);
@morgyface
morgyface / wp_image_orientation.php
Created February 15, 2017 17:19
WordPress | Portrait or Landscape
<?php
$post_thumbnail_id = get_post_thumbnail_id();
$image_attributes = wp_get_attachment_image_src( $post_thumbnail_id, 'full' );
if ( $image_attributes ) {
$width = $image_attributes[1];
$height = $image_attributes[2];
if ( $width > $height ) {
echo get_the_post_thumbnail( $post_id, 'medium', array( 'class' => 'landscape' ) );
} elseif ( $width < $height ) {
echo get_the_post_thumbnail( $post_id, 'medium', array( 'class' => 'portrait' ) );
@morgyface
morgyface / other_posts.php
Last active February 27, 2017 16:42
WordPress | Getting Posts from another WordPress site