Skip to content

Instantly share code, notes, and snippets.

View BryanBarrera's full-sized avatar

Bryan Barrera BryanBarrera

View GitHub Profile
@BryanBarrera
BryanBarrera / twitter-share.js
Last active May 22, 2016 13:39 — forked from guillaumepiot/gist:5442196
Twitter Social Share
// We bind a new event to our link
$('a.tweet').click(function(e){
//We tell our browser not to follow that link
e.preventDefault();
// 1. We get the URL of the link
//or 2. URL of the page
// 1. var loc = $(this).attr('href');
var loc = $(location).attr('href'); // 2
@BryanBarrera
BryanBarrera / functions.php
Last active April 22, 2016 17:19
Remove the Wordpress Logo from the Admin Bar
<?php
/*
This removes the Wordpress Logo from the admin dashboard
Add this snippet to the functions.php file within your theme
*/
function remove_wordpress_logo() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('wp-logo');
}
add_action('wp_before_admin_bar_render', 'remove_wordpress_logo', 0);
@BryanBarrera
BryanBarrera / scrollToTop.js
Created September 25, 2015 02:06
Scroll to the top of the page after certain amount of pixels
// Scroll To Top
jQuery("a[href='#top']").click(function () {
jQuery("html, body").animate({
scrollTop: 0
}, "slow");
return false;
});
// hide button
jQuery('.elementBtn').hide();
@BryanBarrera
BryanBarrera / url.js
Created October 8, 2015 14:12
Show/Hide element based on URL Parameter
// Show #element1 by default
// Show #element1 & #element2 by a unique url string
// --
// ! #element2 is hiding by default with a class of `.hide`
// --
// if the url string is `?sample=one`
// show `#element1` widget and hide the `#peakday` widget
if (location.search == "?sample=one") {
$('#element1').show();
@BryanBarrera
BryanBarrera / hashtag.js
Created January 25, 2016 20:59
animate/scrollTo - if hash is in URL
// if we have anchor on the url
if (window.location.hash) {
// Store the window hash in a variable
var hashname = $(window.location.hash);
// smooth scroll to the id/hash/variable
$('html, body').animate({
scrollTop: hashname.offset().top - 75
}, 500);
}
@BryanBarrera
BryanBarrera / hubspot.boilerplate.css
Created February 1, 2016 17:22
Hubspot Boilerplate CSS
/* @import url('http://example.com/example_style.css'); */
/**
* CSS @imports must be at the top of the file.
* Add them above this section.
*/
/* ==========================================================================
@BryanBarrera
BryanBarrera / Wordpress Data Layer Variables
Last active May 8, 2020 08:35 — forked from chipoglesby/Wordpress Data Layer Variables
Modified Wordpress datalayer variables for pulling: author names, post types, categories, page name, and dates into custom variables for the classic version of Google Analytics. Feel free to leave a comment or hit me up http://BryanBarrera.com
// Add this script after you make your dataLayer = []; call
// AND after your GTM code snippet
// This needs to go inside the header.php in order for it work globally across your site
<script type="text/javascript">
// URL toolbox - helps grabbing elements in the URL
var _d = document;
var _dl = _d.location;
var _dlp = _dl.pathname;
var _dls = _dl.search;
var _dr = _d.referrer;
@BryanBarrera
BryanBarrera / remote-origin-fix.html
Last active August 31, 2020 15:22
fatal: No such remote 'origin' FIX
// If "git remote -v" doesn't show you any remotes you can simply add a remote using:
// Replace https://username@stash/scm/PROJECT/repo.git with your repo URL
git remote add origin https://username@stash/scm/PROJECT/repo.git
@BryanBarrera
BryanBarrera / sanitize-html.php
Last active April 22, 2016 17:19
Sanitize HTML
<?php
/**
* The force_balance_tags() function ensures that no tags are left unclosed,
* while the wp_kses_post() ensures that only safe tags make it into the database
* (the same tags that are allowed in a standard WordPress post.)
* @param int $input.
* @return int sanitizes html input to display output. force_balance_tags checks to see if any html tags are unclosed.
*/
function example_sanitize_text( $input ) {
return wp_kses_post( force_balance_tags( $input ) );
@BryanBarrera
BryanBarrera / font-awesome-sanitize-html.php
Last active April 24, 2016 00:07
Adds font awesome aria-hidden="true" to Wordpress allowed list of tags, mainly used to sanitize callback
<?php /**
* The force_balance_tags() function ensures that no tags are left unclosed,
* we're also using wp_kses to allow font awesome 'aria-hidden' tag to be allowed
*
* @param int $input.
* @return int sanitizes html input to display output. force_balance_tags checks to see if any html tags are unclosed.
*/
function html_sanitize_text($input) {
$filtered = wp_kses($unfiltered, $allowed_html, $allowed_protocols);