Skip to content

Instantly share code, notes, and snippets.

View cssgirl's full-sized avatar
:shipit:

Lindsey cssgirl

:shipit:
View GitHub Profile
@cssgirl
cssgirl / wp-timber-twig-separate-parent-child-terms-taxonomies.twig
Last active August 25, 2020 19:02
WordPress Timber Twig - Separate parent/child taxonomies
{# Set variable containing parent and children terms. #}
{% set taxonomies %}
{# Set taxonomy to be queried #}
{% set taxonomy_name = 'taxonomy_name' %}
{# First gather only the parent terms. #}
{% set parents = post.terms( {query:{taxonomy: taxonomy_name, orderby:'name', order: 'ASC', parent:0}} ) %}
{# Show parents separated by comma #}
{{ parents|join(', ') }}
<br><br>
@cssgirl
cssgirl / vbguest.txt
Last active April 1, 2019 16:13
Vagrant vbguest install
// install vbguest so guest additions are updated when `vagrant up` is run (https://discoposse.com/2016/05/23/autoupdating-virtualbox-guest-additions-with-vagrant-vbguest/)
vagrant plugin install vagrant-vbguest
// Move Yoast to bottom (why is it on top, really?)
function yoasttobottom() {
return 'low';
}
add_filter( 'wpseo_metabox_prio', 'yoasttobottom');
@cssgirl
cssgirl / hero.twig
Last active January 23, 2019 14:17
WordPress: Get a random row of hero data using ACF, groups, repeaters, and twig
{# Check if this is the front/homepage #}
{% if fn('is_front_page') %}
{# store our hero data #}
{% set image = hero_random_img.url %}
{% set title = hero_random_copy %}
{% set link = hero_random_link.url %}
{% set link_title = hero_random_link.title %}
{% set link_target = hero_random_link.target %}
{% set alignment = hero_random_alignment %}
@cssgirl
cssgirl / page-hero.twig
Created September 27, 2018 14:29
Page Hero
{% if is_home %}
{% set hero = post.get_field('hero') %} {# Grab custom field hero group #}
{% set background = hero.background_image %} {# Grab custom field bg image #}
{% else %}
{% set background = post.thumbnail.src('hero') %} {# Otherwise use featured image, with the 'hero' size #}
{% endif %}
{% embed "@components/page-hero/page-hero.twig" with
{
@cssgirl
cssgirl / single.twig
Created September 27, 2018 14:27
Using WP Term Image and WP Term Colors w/ Timber
{# Adding color and image to single template #}
{# Where 'topics'/'topic' is your taxonomy #}
{% set topics = post.terms('topic') %}
{% if topics %}
<div class="taxonomy taxonomy--topic">
{% for term in topics %}
{# User term.meta to grab associated color/bg image #}
<div class="taxonomy__icon" style="background-color:{{ term.meta('color') }}; background-image:url({{ Image(term.meta('image')).src }});"></div>
@cssgirl
cssgirl / author.php
Created September 27, 2018 14:20
Get author info
<?php
/**
* The template for displaying Author Archive pages
*
* Methods for TimberHelper can be found in the /lib sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
*/
@cssgirl
cssgirl / author.php
Created September 27, 2018 14:20
Get author info
<?php
/**
* The template for displaying Author Archive pages
*
* Methods for TimberHelper can be found in the /lib sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
*/
@cssgirl
cssgirl / wp-styles.php
Created September 27, 2018 14:18
Reusable fonts/styles to enqueue
<?php
wp_register_style('clientNameGoogleFonts', 'https://fonts.googleapis.com/css?family=Open+Sans:300,400,400i,600,700,700i,800');
wp_enqueue_style( 'clientNameGoogleFonts');
wp_register_script('fontawesome', get_template_directory_uri() . '/js/lib/fontawesome-all.js', array() );
wp_enqueue_script('fontawesome');
wp_register_script('wowjs', get_template_directory_uri() . '/js/wow.js', array('jquery') );
wp_enqueue_script('wowjs');
@cssgirl
cssgirl / cssgirl-all_cpt-tag_archives.php
Last active September 27, 2018 14:15
Ensure custom post types (CPTs) are included in post_tag (Tag) archive listing pages
<?php
/* When using the default "tags" (post_tag) taxonomy with custom post types in WordPress,
by default, CPTs are not included on the archive listing page.
In your functions.php or custom plugin for your site, add the following to ensure all post
types are included. */
// Changes 'cssgirl' with your own namespace
function cssgirl_all_cpt_tags( $query ) {
if ( $query->is_tag() && $query->is_main_query() ) {