Skip to content

Instantly share code, notes, and snippets.

View tarecord's full-sized avatar
🔨
Hammering Things Into Place

Tanner Record tarecord

🔨
Hammering Things Into Place
View GitHub Profile
@tarecord
tarecord / docker-compose.yml
Created November 27, 2018 20:22
A docker-compose configuration for spinning up local WordPress sites
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- ./mysql:/var/lib/mysql
ports:
- "3306:3306"
restart: always
@tarecord
tarecord / menu_transients.php
Created July 5, 2017 17:54
A function to display a nav menu saved as a transient
<?php
/**
* Menu Transient, a function that helps with extremely large menus by storing the query in a transient
* for ~24hrs. It can be used in template files to both store the transient and display the menu so there
* is no need for multiple functions and queries.
*
* @param $name string A descriptive name of the menu (ex. "mobile-menu" or "quick-links").
* @param $args array The array of nav menu arguments.
*
* @return string The HTML formatted nav menu
@tarecord
tarecord / redirect_attachment_page_to_file.php
Last active October 7, 2023 18:04
Redirect any WordPress attachment page to the actual file
<?php
/**
* Redirect all attachment pages to actual file
*/
function redirect_attachment_pages() {
global $post;
// Return if not an attachment
if ( !is_attachment() ) {
@tarecord
tarecord / get_top_ancestor.php
Created June 6, 2017 18:22
Get the top most parent of a WordPress post
/**
* Gets the top most ancestor for a post.
*
* @param object $post The current post
*
* @return integer The post ID of the ancestor
*/
function get_top_ancestor( $post ) {
if ( $post->post_parent ) {
$ancestors = get_post_ancestors( $post->ID );