Skip to content

Instantly share code, notes, and snippets.

View pixeldevsio's full-sized avatar
👋
Come say Hi!

David H pixeldevsio

👋
Come say Hi!
View GitHub Profile
<?php
/**
* Update Single Post Content images to include image credit
*
* @param string $content
* @return string
*/
function _codeable_addCreditToImage(string $content){
global $post;
@pixeldevsio
pixeldevsio / custom-parent-child-page-template.php
Created December 10, 2021 20:01
Create custom WordPress structure for parent child page templates.
<?php
add_filter(
'page_template',
function ($template) {
global $post;
if ($post->post_parent) {
// get top level parent page
$parent = get_post(
reset(array_reverse(get_post_ancestors($post->ID)))
@pixeldevsio
pixeldevsio / ParentAndChildPageTemplatesWordPress.php
Last active October 27, 2021 12:35
WordPress Parent and Child Page templates
<?php
// Use this function to add Parent and Child Page Templates
// Structure:
// theme_folder/page-templates/parent_page_slug/page.php - Parent Template
// theme_folder/page-templates/parent_page_slug/page-child_page_slug.php - Child Template
// theme_folder/page-templates/parent_page_slug/page-child_page_ID.php - Child Template
add_filter(
'page_template',
function ($template) {
@pixeldevsio
pixeldevsio / wp-cleanup.php
Created April 27, 2021 11:37
Clean up the WP Head
<?php
/********** CLEANUP *************/
/**
* Disable the emoji's
*/
function disable_emojis() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
<?php
// Highlight menu item if child is loaded
function custom_active_item_classes($classes = array(), $menu_item = false){
global $post;
$classes[] = ($menu_item->url == get_post_type_archive_link($post->post_type)) ? 'current-menu-item active' : '';
return $classes;
}
add_filter( 'nav_menu_css_class', 'custom_active_item_classes', 10, 2 );
?>
@pixeldevsio
pixeldevsio / HumanMade S3 Digital Ocean Instructions
Last active May 2, 2024 06:57
Use HumanMade S3 plugin with Digital Ocean Spaces
These are the two steps you need to take to get S3 to work with Digital Ocean Spaces.
https://github.com/humanmade/S3-Uploads
@pixeldevsio
pixeldevsio / pd_display_child_terms.php
Last active March 20, 2021 10:50
WordPress helper functions to display child terms by parent slug
<?php
// helper function to get term children
function pd_get_term_children($slug, $term_type = 'category'){
// set up category by slug
$category = get_term_by('slug', "{$slug}", "{$term_type}");
// get out if no category
if(!$category){return;}
<?php
/**
* Add Phone field to Shipping on checkout page
* Validation automatically happens since we set it via WooCommerce Hook
*/
add_filter( 'woocommerce_checkout_fields', 'custom_override_default_address_fields' );
function custom_override_default_address_fields($fields){
// Get access to WooCommerce and grab the current billing and shipping countries on page load.
global $woocommerce;
$billingCountryCode = $woocommerce->customer->get_billing_country();
@pixeldevsio
pixeldevsio / tribe-events-calendar-google-calendar-link-modify.php
Last active January 30, 2020 15:27
Modify Google Calendar link parameters for Tribe Events Calendar (includes multi-day events)