Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View tessak22's full-sized avatar
🚀
Cultivating Developer Community @Snapchat

Tessa Kriesel tessak22

🚀
Cultivating Developer Community @Snapchat
View GitHub Profile
@tessak22
tessak22 / functions.php
Created December 10, 2017 17:46
Create Custom Post Type in WordPress
add_action('init', 'tessak22_register_custom_post_types', 0);
function tessak22_register_custom_post_types()
{
$arr_custom_post_type_options = array(
/*
array(
'label' => 'lowercase_name' // ** 20 char max, no spaces or caps
'singlar' => 'Human-Readable Item' // singular name
'plural' => 'Human-Readable Items' // plural name
'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes', 'post-formats')
@tessak22
tessak22 / upcoming-events.php
Created December 10, 2017 18:01
Templating for Custom Post Type sorting by ACF Date Field
<?php
$today = current_time('Ymd');
$args = array(
'post_type' => 'events',
'posts_per_page' => '20',
'meta_key' => 'speaking_date',
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_query' => array(
array(
@tessak22
tessak22 / template-file.php
Created December 11, 2017 16:36
Advanced Custom Fields IF Statements
//Used in Template
<?php if(get_field('banner_image')): ?>
<div class="banner-image"><img class="img-responsive" src="<?php the_field('banner_image'); ?>"></div>
<?php endif; ?>
//Used in custom post types
<?php
@tessak22
tessak22 / page.php
Created October 5, 2018 17:38
ACF Page Builder - Add to template file
<?php //each page builder has its own section
get_template_part('inc', 'page-builder');
?>
@tessak22
tessak22 / inc-page-builder.php
Last active October 5, 2018 17:39
ACF Page Builder - Create file and put in template root directory
<?php
// loop over the ACF flexible fields for this page / post
while ( the_flexible_field('page_builder') ) {
// load the layout from the block folder
get_template_part( 'blocks/'. get_row_layout() );
} ?>
@tessak22
tessak22 / centered_paragraph_with_title.php
Created October 5, 2018 17:42
ACF Page Builder - Blocks - Centered Paragraph with Title (Create a "blocks" directory in your theme directory and place in there)
<?php
$title = get_sub_field('title');
$content = get_sub_field('content');
?>
<section class="content-block centered_paragraph_with_title flex">
<div class="content col-sm-10 col-sm-offset-1 text-center">
<?php if ( $title ): ?>
<h3><?php echo $title; ?></h3>
@tessak22
tessak22 / functions.php
Created October 5, 2018 18:19
Dogs Custom Post Type
// Custom Post Types
add_action('init', 'tessak22_register_custom_post_types', 0);
function tessak22_register_custom_post_types()
{
$arr_custom_post_type_options = array(
/*
array(
'label' => 'lowercase_name' // ** 20 char max, no spaces or caps
'singlar' => 'Human-Readable Item' // singular name
'plural' => 'Human-Readable Items' // plural name
@tessak22
tessak22 / page-dogs.php
Created October 5, 2018 18:21
Page template to display my Dogs Custom Post Type
<?php
/**
* Template Name: Dogs
*
* @link https://codex.wordpress.org/Template_Hierarchy
*
* @package WordPress
* @subpackage Twenty_Seventeen
* @since 1.0
* @version 1.0
@tessak22
tessak22 / functions.php
Created October 5, 2018 21:07
Options Page for Theme Settings with ACF
/**
* Add ACF Options for Theme Settings
*/
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Theme Settings',
'menu_title' => 'Theme Settings',
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
@tessak22
tessak22 / function.php
Last active February 21, 2019 16:56
Hero ACF Block (Requires ACF Pro 5.8)
/**
* Register hero block
*/
add_action('acf/init', 'hero');
function hero() {
// check function exists
if( function_exists('acf_register_block') ) {
// register a hero block