Skip to content

Instantly share code, notes, and snippets.

View dannydickson's full-sized avatar

Danny D. dannydickson

View GitHub Profile
@dannydickson
dannydickson / custom-post-navigation.php
Last active December 11, 2022 20:58
WordPress custom post navigation inside of a shortcode
<?php
function custom_post_navigation_function() {
ob_start();
// Setup and store previous post variables
$prev_post = get_previous_post();
$prev_id = $prev_post->ID;
$prev_title = $prev_post->post_title;
$prev_link = get_permalink( $prev_id );
@dannydickson
dannydickson / multi-location-json-schema.json
Created May 5, 2022 16:00
Multiple location schema JSON structured data
{
"@context": {
"@vocab": "http://schema.org/"
},
"@graph": [
{
"@id": "https://bayareaboatrentals.com",
"@type": "Organization",
"name": "Bay Area Boat Rentals",
"url" : "https://bayareaboatrental.com/",
@dannydickson
dannydickson / acf-flexible-or-standard-content.php
Created April 29, 2021 23:08
If we have ACF flexible content rows setup on the page, display those. Otherwise, display the standard content.
<?php
// If have flexible content rows
if (have_rows('layouts')) :
while (have_rows('layouts')) : the_row();
$class = 'container';
if (get_sub_field('background_color')) {
$class .= ' ' . get_sub_field('background_color');
}
@dannydickson
dannydickson / parks-greenways-blog-loop-for-sidebar.php
Last active April 29, 2021 23:09
CCPR - Parks and Greenways Single Post Loop for Sidebar
<?php
/*
* The WordPress Query class.
*
* @link http://codex.wordpress.org/Function_Reference/WP_Query
*/
$args = array(
'p' => get_field('blog_post'),
'posts_per_page' => 1,
);
@dannydickson
dannydickson / tailwind-profile-button.html
Created February 20, 2020 13:15
Tailwind Profile Button with Dropdown and Avatar Header
<! –– Taken from https://polished-sunset-0ex44e5cb9xt.tailwindcss.com/previews/mZOl4nEdBiYkg9Nw ––>
<div id="dropdown" class="relative inline-block">
<button
@click="isOpen = true"
class="inline-flex items-center pl-6 pr-2 py-2 font-semibold text-white bg-gray-800 rounded-lg hover:bg-gray-700 focus:outline-none focus:shadow-outline active:bg-gray-900"
>
Account
<svg
class="ml-2 h-6 w-6 text-white"
@dannydickson
dannydickson / tailwind-navigation-with-mobile-slide-in.html
Created February 20, 2020 13:12
Tailwind Navigation Example with Mobile Off-Screen Menu
<! –– Taken from Adam Wathan here:https://polished-sunset-0ex44e5cb9xt.tailwindcss.com/previews/mZOl4nEdBiYkg9Nw ––>
<div class="bg-gray-200" style="min-height: 640px;">
<div id="nav" class="bg-white shadow">
<div class="md:px-8">
<nav
class="relative flex flex-wrap items-center justify-between md:py-4"
>
<div class="relative z-10 flex-shrink-0 pl-4 py-4 md:p-0">
<img class="h-8 w-8" src="/img/example-logo.svg" alt="" />
@dannydickson
dannydickson / add-link-to-wp-admin-bar.php
Last active February 11, 2020 18:46
Add custom link to WP admin bar
@dannydickson
dannydickson / dynamic-classes-wp-menu-items.php
Created October 19, 2019 00:01
Add dynamic ACF classes to WordPress menu items (used for dynamically changing colors based on ACF field. Utilizes Tailwind CSS utility classes)
/**
* Adds custom classes to WP Menu Items in Primary theme menu (header)
*/
function header_menu_classes( $classes, $item, $args ) {
// Store primary color and saturation from ACF as variable
$primary_color = get_field('primary_color', 'option');
$primary_color_saturation = get_field('primary_color_saturation', 'option');
// If menu-1 aka primary theme menu filter the classes for WP menu-items
if ( 'menu-1' === $args->theme_location ) {
// adds custom classes including dynamic primary color
@dannydickson
dannydickson / dark-theme.css
Last active August 20, 2019 20:03
My Slack Dark Theme CSS File
.p-unreads_view__header {
background: #545454 !important;
color: #222 !important;
}
::-moz-placeholder {
color: #e6e6e6 !important;
filter: none;
opacity: 0.5;
}
@dannydickson
dannydickson / sort-by-custom-field.php
Last active July 11, 2019 23:32
Sort by custom field in WordPress
<?php
// Taken and modified from https://www.advancedcustomfields.com/resources/orde-posts-by-custom-fields/
// Put here for posterity's sake as a bookmark of sorts
// Allows sorting by custom field value instead of default.
// This will allow client to be able to set the order of these goals/landing pages as they add more.
// Can be added to functions.php, or to custom template that gets called before your custom loop.
function my_pre_get_posts( $query ) {
// do not modify queries in the admin