Skip to content

Instantly share code, notes, and snippets.

View CrisHazzard's full-sized avatar

Cris Hazzard CrisHazzard

View GitHub Profile
@CrisHazzard
CrisHazzard / functions.php
Created January 13, 2017 14:27
Display 2D Array As Table
$out = "";
$out .= "<table>";
foreach($arrayname as $key => $element){
$out .= "<tr>";
foreach($element as $subkey => $subelement){
$out .= "<td>$subelement</td>";
}
$out .= "</tr>";
}
$out .= "</table>";
@CrisHazzard
CrisHazzard / functions.php
Created October 21, 2016 13:15
Redirect Pages with /AMP/ to a different Wordpress Page Template on HikingGuy.com
// ****************************************************************************************************
// AMP support
define( 'AMP_QUERY_VAR', apply_filters( 'amp_query_var', 'amp' ) );
add_rewrite_endpoint( AMP_QUERY_VAR, EP_PERMALINK );
add_filter( 'template_include', 'amp_page_template', 99 );
function amp_page_template( $template ) {
@CrisHazzard
CrisHazzard / functions.php
Created October 21, 2016 13:12
Video Sitemap using ACF field for YouTube Video on HikingGuy.com
// ****************************************************************************************************
// Video Sitemap
add_action( "save_post", "eg_create_sitemap" );
function eg_create_sitemap() {
// youtube_video is the ACF video where I store the normal YouTube link
$args = array(
@CrisHazzard
CrisHazzard / After-Load-JS.js
Created July 5, 2016 14:21
AJAX Lazy Load Google Maps After Page Load (doesn't affect initial page load)
jQuery( window ).load(function() {
// This jQuery event only triggers after the first time a user scrolls. Your map loads once they scroll. This only makes sense if the map is below the fold
jQuery( window ).one( "scroll", function() {
loadAPI();
});
@CrisHazzard
CrisHazzard / gist:659f54ba4e4de30c665e24d5ce81e9dd
Created July 5, 2016 13:52
SQL Script to Remove leading directory from SQL field
UPDATE `table_name` SET `field_value` = SUBSTRING_INDEX(field_value, /', -1) WHERE `col_value` = 'col_match'
<?
//------------------------------------------------------------------------------
// Escape HTML tags in post content
add_filter('the_content', 'escape_code_fragments');
// Escape HTML tags in comments
add_filter('pre_comment_content', 'escape_code_fragments');
function escape_code_fragments($source) {
@CrisHazzard
CrisHazzard / wordpress-remove-fixed-width-captions.php
Last active July 5, 2016 14:10
WordPress adds fixed widths to divs with image captions. Add this code to your functions.php file to remove the fixed width and height so you can properly style with CSS.
<?php
//------------------------------------------------------------------------------
// Remove height and width automatic from image captions
add_shortcode('wp_caption', 'fixed_img_caption_shortcode');
add_shortcode('caption', 'fixed_img_caption_shortcode');
function fixed_img_caption_shortcode($attr, $content = null) {
if ( ! isset( $attr['caption'] ) ) {
if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches ) ) {