Skip to content

Instantly share code, notes, and snippets.

View morgyface's full-sized avatar

Dan morgyface

View GitHub Profile
@morgyface
morgyface / social.php
Last active March 8, 2025 21:38
WordPress | ACF | Social Media Links using Advanced Custom Fields and FontAwesome
<?php
if( have_rows('social_media', 'option') ):
echo '<div class="container social my-4">';
echo '<p class="follow mb-0 align-middle">Follow us</p>';
echo '<ul class="nav align-middle">';
while ( have_rows('social_media', 'option') ) : the_row();
$socialchannel = get_sub_field('social_channel', 'option');
$socialurl = get_sub_field('social_url', 'option');
echo '<li class="nav-item">';
echo '<a class="nav-link" rel="nofollow noopener noreferrer" href="' . $socialurl . '" target="_blank">';
@morgyface
morgyface / functions_custom-cols.php
Last active April 25, 2025 13:46
WordPress | Advanced Custom Fields | Create custom columns within admin for a custom post type using ACF
<?php
// Change the columns for the releases list screen
function change_columns( $cols ) {
$cols = array(
'cb' => '<input type="checkbox" />',
'featimg' => 'Featured Image',
'excerpt' => 'Excerpt?',
'title' => 'Title',
'artist' => 'Artist',
'catno' => 'Cat#',
@morgyface
morgyface / featured-image_or_placeholder.php
Last active July 12, 2016 08:32
WordPress | If no featured image show a generic image
@morgyface
morgyface / not-empty-content.php
Created July 15, 2016 13:36
WordPress | Only display content if NOT empty
<?php
$content = get_the_content();
if( !empty( $content ) ) {
echo '<div class="content">';
the_content();
echo '</div>';
}
?>
@morgyface
morgyface / category-list.php
Last active July 15, 2016 21:49
WordPress | Comma seperated list of all categories assigned to a post without links
<?php
if ( has_category() ) {
echo '<span>';
$categories = get_the_category();
$total = count( $categories );
$catcount = 1;
foreach( $categories as $category ) {
$catname = $category->cat_name;
echo $catname;
if ( $catcount != $total ) {
@morgyface
morgyface / faq.php
Created July 21, 2016 10:09
Wordpress | ACF | FAQs
<style>
div.questions {padding:4em 0; clear:both}
div.questions h2 {font-size:2em; color:#111}
div.questions ul {margin:2em auto; max-width:800px; padding:0; list-style:none; font-size:1em; line-height:3em}
div.questions ul li {border-top:1px solid #DDD}
div.questions ul li a {color:#07F; border-bottom:1px solid transparent; -webkit-transition:border-color 0.5s ease-in-out; -moz-transition:border-color 0.5s ease-in-out; -o-transition:border-color 0.5s ease-in-out; transition:border-color 0.5s ease-in-out}
div.questions ul li a:hover {border-color:#07F}
div.faqs {background-color:#DDD; padding:1em 0; clear:both}
div.faqs dl {width:100%; max-width:800px; margin:0 auto}
div.faqs dl dt {font-size:3em; color:#111; margin:0 0 1em 0; padding-top:2em}
@morgyface
morgyface / cf7.php
Last active February 8, 2017 09:44
WordPress | Contact Form 7
<style>
/* Standard fields and elements */
div.wpcf7 form.wpcf7-form label {}
div.wpcf7 form.wpcf7-form input.wpcf7-text,
div.wpcf7 form.wpcf7-form textarea {width:calc(98% - 2px); padding:0.4em 1%; border-width:1px; border-style:solid}
div.wpcf7 form.wpcf7-form select {}
div.wpcf7 form.wpcf7-form input.wpcf7-submit {}
/* Validation and messages */
div.wpcf7 form.wpcf7-form span.wpcf7-not-valid-tip {display:block; font-size:1em} /* the prompt that appears under a field */
div.wpcf7 form.wpcf7-form div.wpcf7-response-output {margin:2em 0.5em 1em 0.5em; padding:0.2em 1em; border-width:2px; border-style:solid} /* the larger alert that appears under the form following a submission */
@morgyface
morgyface / map.php
Last active July 4, 2017 11:36
Wordpress | ACF | Google JavaScript Custom Map
<style>
div#map {width: 100%; height: 40vh}
</style>
<?php
if ( is_page( 'Contact' ) ) {
$api_key = get_field('api_key');
$marker = get_field('marker_image');
$latitude = get_field('latitude');
$longitude = get_field('longitude');
$zoom = get_field('zoom');
@morgyface
morgyface / get_posts_acf.php
Created August 2, 2016 09:11
WordPress | Get posts that do NOT have a custom field
<?php
global $post;
$args = array(
'posts_per_page' => 15,
'post_type' => 'post',
'meta_query' => array(
array(
'key' => 'feature',
'value' => 0
)
@morgyface
morgyface / get_posts_adaptive_columns.php
Last active April 15, 2017 17:17
WordPress | Get Posts with adaptive column widths
<style>
ul {margin:0; padding:0; list-style:none; overflow:auto}
ul li {float:left}
ul.half li {width:50%}
ul.thirds li {width:33.33%; width:calc(100% / 3)}
ul.quarters li {width:25%}
</style>
<?php
$args = array(
'posts_per_page' => 100,