Skip to content

Instantly share code, notes, and snippets.

@brycejacobson
brycejacobson / woocommerce-optimize-scripts.php
Created October 13, 2022 13:29 — forked from DevinWalker/woocommerce-optimize-scripts.php
Only load WooCommerce scripts on shop pages and checkout + cart
/**
* Optimize WooCommerce Scripts
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*/
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//remove generator meta tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
@brycejacobson
brycejacobson / functions.php
Created July 7, 2021 20:18
ACF Get Videos from Oembed and Custom Thumbnail Size
<?php
/**
* Get youtube video ID from URL
*
* @param string $url the video url.
* @return string Youtube video id or FALSE if none found.
*/
function youtube_id_from_url( $url ) {
$pattern =
'%^# Match any youtube URL
@brycejacobson
brycejacobson / functions.php
Created October 23, 2020 20:00
Redirect Employee After Login
<?php
/**
* Redirect user after successful login.
*
* @param string $redirect_to URL to redirect to.
* @param string $request URL the user is coming from.
* @param object $user Logged user's data.
* @return string
*/
@brycejacobson
brycejacobson / acf-with-standards.php
Last active May 4, 2020 17:27
ACF Fields with Coding Standards
<?php if ( $phone = get_field( 'phone' ) ) : ?>
<?php echo esc_html( $phone ); ?>
<?php endif; ?>
<?php if ( $email = get_field( 'email' ) ) : ?>
<a href="mailto:<?php echo $email; ?>"><?php echo $email; ?></a>
<?php endif; ?>
<?php echo esc_url( get_field( 'website' ) ); ?>
<?php
@brycejacobson
brycejacobson / acf-non-standard.php
Created May 4, 2020 17:08
ACF Fields with no Coding Standards
<?php if ( $phone = get_field('phone') ): ?>
<?php echo esc_html($phone); ?>
<?php endif; ?>
<?php if ( $email = get_field('email') ): ?>
<a href="mailto:<?php echo $email; ?>"><?php echo $email; ?></a>
<?php endif; ?>
<?php echo esc_url(get_field('website')); ?>
<?php
@brycejacobson
brycejacobson / single.php
Last active April 28, 2020 20:42
WordPress show previous/next post navigation with thumbnail.
<?php
// Get previous post.
$previous_post = get_previous_post( true );
if ( ! empty( $previous_post ) ) {
$prev_thumbnail = get_the_post_thumbnail( $previous_post->ID, 'thumbnail' );
} else {
$prev_thumbnail = '';
}
// Get next post.
$next_post = get_next_post( true );
@brycejacobson
brycejacobson / single.php
Last active February 27, 2020 15:11
WordPress Post Navigation for Private Posts
<nav class="navigation post-navigation" role="navigation" aria-label="Posts">
<h2 class="screen-reader-text">Post Navigation</h2>
<div class="nav-links">
<?php
global $wpdb;
$results = $wpdb->get_results(
$wpdb->prepare(
"
SELECT *
FROM $wpdb->posts
@brycejacobson
brycejacobson / content-featured-videos.php
Created May 24, 2019 19:12
ACF Featured Videos Slider YouTube oEmbed
@brycejacobson
brycejacobson / sidebar.php
Last active October 29, 2018 16:39
Get List of WordPress Custom Taxonomy Terms and Display Both Parent and Child
<?php
<ul class="vertical menu accordion-menu" data-accordion-menu>
<li>
<a href="#" class="accordion-menu__title">Categories</a>
<?php
$dinecategory = get_terms(
'dinecategory',
array(
@brycejacobson
brycejacobson / theme-functions.php
Created August 28, 2018 20:08
Set sizes attribute for responsive images and better performance in WordPress
<?php
/**
* Set sizes attribute for responsive images and better performance
*
* @param array $attr markup attributes.
* @param object $attachment WP_Post image attachment post.
* @param string|array $size named image size or array.
* @return array markup attributes
*/