Skip to content

Instantly share code, notes, and snippets.

View eccentricpixel's full-sized avatar

Eccentric Pixel eccentricpixel

View GitHub Profile
@eccentricpixel
eccentricpixel / gist:2671c2876086af55439a
Created July 21, 2014 01:30
PHP and shortcodes in widgets. Put in theme's function file.
// Enable PHP in widgets
add_filter('widget_text','execute_php',100);
function execute_php($html){
if(strpos($html,"<"."?php")!==false){
ob_start();
eval("?".">".$html);
$html=ob_get_contents();
ob_end_clean();
}
return $html;
@eccentricpixel
eccentricpixel / gist:10836052
Created April 16, 2014 08:54
Add page animations prior to following a link. Here it is setup for the main navigation, using GSAP for animation.
function closePage(href) {
var pageSwitching = new TimelineMax({ paused: true});
pageSwitching.insert(TweenLite.to($('#contentShell'), 1.25, {css:{ autoAlpha: 0, top: 1400 }, ease: Expo.easeInOut}), .1);
pageSwitching.insert(TweenLite.to('#top_bg', 1, {css:{autoAlpha:0, top:-900}, ease: Expo.easeInOut}), 0.15);
pageSwitching.play();
setTimeout(function() {
@eccentricpixel
eccentricpixel / gist:10035980
Created April 7, 2014 19:29
Creates dropdown menu animation using GSAP (Greensock). Set .dropdown with overflow:hidden and remove min-height or set to 0. Markup for menu would be <ul id="main_menu"><li><a href="#">something</a></li><li class="has-dropdown"><a href="#">something with submenu</a><ul class="dropdown"><li>something</li><li>sdfg</li></ul></li></ul>
// main navigation
var subMenus = $("#main_menu .dropdown");
$.each($("li.has-dropdown"), function(index, element)
{
var subMenu = $(element).children('ul'),
tl;
if(subMenu.length != 0)
@eccentricpixel
eccentricpixel / gist:8742933
Created January 31, 2014 20:54
Here is a more full-proof way to ensure Wordpress does not throw your items out of sequence (2,24,25,3,4,5,51,6...etc). Ideally use a num field type instead of plain text.
'orderby'=>'CAST( sort_order.meta_value AS SIGNED ) DESC'
@eccentricpixel
eccentricpixel / gist:8480112
Created January 17, 2014 19:45
Adds a span tag of the TITLE attribute in the output of Wordpress menus
add_filter('walker_nav_menu_start_el', 'description_in_nav_el', 10, 4);
function description_in_nav_el($item_output, $item, $depth, $args)
{
return preg_replace('/(<a.*?>[^<]*?)</', "<span>{$item->attr_title}</span>" . '$1' . "<", $item_output);
}
@eccentricpixel
eccentricpixel / gist:6617167
Created September 18, 2013 23:23
Simple age gate scenario where cookies are not needed but validation of a user's age is required to progress to a new screen.
// Add this to your js
/* start cart age check */
$('input[name="checkout"], input[name="goto_pp"], input[name="goto_gc"]').click(function() {
var day = $("#theDay").val();
var month = $("#theMonth").val();
var year = $("#theYear").val();
var age = 21;
var birthdate = new Date();
@eccentricpixel
eccentricpixel / backstretch and dynamic images
Last active December 22, 2015 01:28
Setup a loop in php to get your array of values and then echo those values inside of backstretch or other js functions. Below is an example of using PODS to pull a marquee image from a CPT created with Pods. While you can use php directly inside your script tag, the js functionality will not work properly; for instance, in the case of Backstretc…
<?php
$counter = 0;
$marqueesParams = array('limit'=> 20);
$marquees = pods('marquee');
$marquees->find($marqueesParams);
if (0 < $marquees->total()){
while ($marquees->fetch()) {
$artwork = $item->field('marquee_artwork');
foreach($artwork as $art) {
jQuery(document).ready(function ($) {
resizeDiv();
function resizeDiv() {
@eccentricpixel
eccentricpixel / gist:5854631
Created June 24, 2013 23:22
a way to detect what browser you are in just with javascript
var isOpera = !!window.opera || navigator.userAgent.indexOf('Opera') >= 0;
// Opera 8.0+ (UA detection to detect Blink/v8-powered Opera)
var isFirefox = typeof InstallTrigger !== 'undefined'; // Firefox 1.0+
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
// At least Safari 3+: "[object HTMLElementConstructor]"
var isChrome = !!window.chrome; // Chrome 1+
var isIE = /*@cc_on!@*/false; // At least IE6
document.write('isFirefox: ' + isFirefox + '<br>');
document.write('isChrome: ' + isChrome + '<br>');