Skip to content

Instantly share code, notes, and snippets.

View chriswagoner's full-sized avatar

Chris Wagoner chriswagoner

  • Chicago
View GitHub Profile
@chriswagoner
chriswagoner / get_tabs.php
Created March 12, 2020 19:24
A shortcode that will get Tabs from woocommerce products so you can output in a tabular fashion. This is part 1 of 2. You must have an attribute called tabs for this to work.
/**
* Eg : [gettabs category="hydraulic" type="slug"]
* Shortcode for getting a list of tabs from a product category
*
* Shortcode attributes :
* type (optional): type of resultset values returned (slug or id) Default: slug
* category (required): slug of product category
*
* returns comma-separated string of tab slugs or tab ids
*/
// ================================================================================================
// FLIPPING THE GET SHORTCODE TO GET CATS IN A RESTRICTED FASHION ^CW
// ================================================================================================
/**
* Eg : [getcats type="slug"]
* Shortcode for getting a list of categories from a current product category & restricted by product brand
*
* Shortcode attributes :
* type (optional): type of resultset values returned (slug or id) Default: slug
@chriswagoner
chriswagoner / remove_woocommerce_lightbox.php
Created January 26, 2021 19:43
Remove the WooCommerce Lightbox Effect
/**
* Remove WooCommerce Lightbox
*/
add_action( 'init', 'my_remove_lightbox' );
function my_remove_lightbox() {
remove_theme_support( 'wc-product-gallery-lightbox' );
}
@chriswagoner
chriswagoner / get_this_post.php
Created April 12, 2021 19:12
Get the ID of this post
add_shortcode( 'return_post_id', 'gimme_post_id' );
function gimme_post_id() {
return get_the_ID();
}
@chriswagoner
chriswagoner / acf_date_format.php
Created May 13, 2021 13:17
Advanced Custom Fields ACF shortcode for date format output
function acf_event_date( $atts )
{
// extract attributes
extract( shortcode_atts( array(
'field' => '',
'post_id' => false,
'format_value' => true,
'date_format' => ''
), $atts ) );
@chriswagoner
chriswagoner / convert_yt_to_embed.php
Created June 2, 2021 18:54
Convert YouTube URLs to Embed URLs
function go_convert_youtube_url_to_embed_url($youtube_url) {
$matches = array();
preg_match('/((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?/', $youtube_url, $matches);
return "https://www.youtube.com/embed/".$matches[5];
}
@chriswagoner
chriswagoner / inject_os_browser_class.php
Created July 2, 2021 18:47
WP Inject OS Browser Class
//// Browser/OS Body Class
function mv_browser_body_class($classes) {
global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
if($is_lynx) $classes[] = 'lynx';
elseif($is_gecko) $classes[] = 'gecko';
elseif($is_opera) $classes[] = 'opera';
elseif($is_NS4) $classes[] = 'ns4';
elseif($is_safari) $classes[] = 'safari';
elseif($is_chrome) $classes[] = 'chrome';
elseif($is_IE) {
@chriswagoner
chriswagoner / child_page_list
Created October 5, 2021 20:12
Get the child or sibling pages
function mysite_child_pages() {
global $post;
if ( is_page() && $post->post_parent )
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
else
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );
@chriswagoner
chriswagoner / generate-basic-fluid.css
Created December 15, 2021 14:23
GeneratePress Basic Fluid Styles
/* Base HTML */
html {
font-size: 62.5%;
}
p {
font-size: clamp(1.4rem, calc(1.4rem + ((1vw - 0.32rem) * 0.4545)), 1.8rem);
}
@chriswagoner
chriswagoner / acf_repeater_fields
Last active January 26, 2022 15:43
ACF_Repeater_Fields
add_shortcode( "the_shortcode", "the_function" );
function the_function() {
ob_start();
// Run the loop - Do we have a Repeater field?
if ( have_rows( 'repeater_field_name' ) ) :
echo '<div class="myclass">'; // Optional if you want to output before the fields