Skip to content

Instantly share code, notes, and snippets.

View EastSideCode's full-sized avatar

East Side Code EastSideCode

View GitHub Profile
@EastSideCode
EastSideCode / functions.php
Created April 7, 2018 15:40
Alternate contact form 7 tracking
jQuery(document).ajaxComplete(function() {
if (jQuery('.wpcf7-mail-sent-ok').length) {
if (typeof gtag !== 'undefined') {
gtag('event', 'Submit', {
'event_category': 'Contact Form',
'event_callback': function() {
console.log("contact form tracking sent successfully");
}
});
@EastSideCode
EastSideCode / functions.php
Created April 7, 2018 15:53
Analytics tracking for google maps directions
// track directions
jQuery('body').on("click", "a[href*='maps.google.com']", function(event) {
if (typeof gtag !== 'undefined') {
gtag('event', 'Click', {
'event_category': 'Contact',
@EastSideCode
EastSideCode / scroll-add-class.js
Created April 10, 2018 13:14
Add a class to an element on page scroll
jQuery(window).scroll(function($) {
var scroll = $(window).scrollTop();
if (scroll >= 500) {
$(".element").addClass("sample-class-to-add");
} else {
$(".element").removeClass("sample-class-to-add");
}
});
@EastSideCode
EastSideCode / HTML And CSS
Created April 16, 2018 15:10
Grid system
<!-- SAMPLE MARKUP -->
<div class="section group">
<div class="col span_1_of_12">
1 of 12
</div>
<div class="col span_1_of_12">
1 of 12
</div>
<div class="col span_1_of_12">
1 of 12
@EastSideCode
EastSideCode / functions.php
Created April 16, 2018 16:01
Goal Tracking Master
// Include the Google Analytics Tracking Code
function google_analytics_tracking_code(){ ?>
<!-- script from analytics starts here -->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-68863234-2"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
@EastSideCode
EastSideCode / template-redirect-child.php
Created April 18, 2018 13:17
Page template to redirect to the first child page in WordPress
<?php
/*
Template Name: Redirect To First Child
*/
if (have_posts()) {
while (have_posts()) {
the_post();
$pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
$firstchild = $pagekids[0];
wp_redirect(get_permalink($firstchild->ID));
@EastSideCode
EastSideCode / template-name.php
Created April 28, 2018 16:28
Get Featured image information in WordPress
<?php $image_data = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "thumbnail" ); ?>
<?php $image_width = $image_data[1]; ?>
@EastSideCode
EastSideCode / functions.php
Created April 29, 2018 17:12
Adding Meta Boxes
/*
3 steps
1. Create the meta field
2. Display is in the admin area
3. Add a save feature that checks the nonce created in the display function
*/
// add homepage meta box
@EastSideCode
EastSideCode / functions.php
Created April 30, 2018 20:38
For development mode, check if user is logged in
<?php
// for development
$developmentMode = false;
$userLoggedIn = is_user_logged_in();
$currentUser = wp_get_current_user();
if (($currentUser->user_login == "lfico") && $userLoggedIn) {
$developmentMode = true;
}
@EastSideCode
EastSideCode / page-template.php
Created May 3, 2018 14:57
Add html sitemap to pages
<div class="html-sitemap">
<h2>Author(s):</h2>
<ul class="sitemap-authors">
<?php
//http://codex.wordpress.org/Function_Reference/wp_list_authors
wp_list_authors('exclude_admin=1&optioncount=1');
?>
</ul>
<h2>Pages:</h2>