Skip to content

Instantly share code, notes, and snippets.

View erickarbe's full-sized avatar

Erick Arbé erickarbe

View GitHub Profile
@erickarbe
erickarbe / jquery.scroll-addClass.js
Last active December 11, 2015 05:38 — forked from danott/jquery.scroll-lock.js
Boom. I just modified this plugin to simply add a class to the body tag when the "lockElement" reaches your offset point. This makes using this plugin MUCH easier with responsive designs. Simply utilize it with your media queries.
(function($) {
var defaults = {};
$.fn.fixedscroll = function(opts) {
var options = $.extend(defaults, opts);
var el = $(this);
@erickarbe
erickarbe / gist:4932027
Created February 13, 2013 02:51
Easy jQuery Accordion Functionality for RWD Navigation
var menu = $j('#menu'),
menulink = $j('.menu-link'),
menuTrigger = $j('.has-submenu > a');
menulink.click(function(e) {
e.preventDefault();
menulink.toggleClass('active');
menu.toggleClass('active');
});
@erickarbe
erickarbe / gist:5257290
Created March 27, 2013 19:31
WordPress Logout Shortcode
//Logout Shortcode
function logout_func ($atts, $content = null) {
extract(shortcode_atts(array(
'linktext' => 'Log Out',
), $atts));
$logoutlink = wp_logout_url( home_url() );
return '<a href="' . $logoutlink . '" title="Logout">'. $linktext .'</a>';
}
add_shortcode( 'wplogout', 'logout_func' );
?>
@erickarbe
erickarbe / gist:8700464
Created January 30, 2014 00:46
Simple pagination for WordPress loops
<?php
function simple_pagination($pages = '', $range = 2){
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == '')
{
@erickarbe
erickarbe / gist:5ad0f24cc68f1061e46d506b2f25b4fe
Created March 28, 2017 15:06
Add rel="nofollow" to only PDF links in Wordpress content and excerpt
add_filter('the_content', 'my_nofollow');
add_filter('the_excerpt', 'my_nofollow');
function my_nofollow($content) {
return preg_replace_callback('/<a[^>]+\\.pdf/', 'my_nofollow_callback', $content);
}
function my_nofollow_callback($matches) {
$link = $matches[0];
$link = preg_replace("%(href=\S(?!$link))%i", 'rel="nofollow" $1', $link);
return $link;
}
@erickarbe
erickarbe / 0_reuse_code.js
Created June 13, 2017 14:19
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@erickarbe
erickarbe / new_gist_file_0
Created June 29, 2017 14:21
Multi Toggle JS
jQuery( document ).ready( function( $ ) {
var $menu = $('#menu'),
$menulink = $('.menu-link'),
$menuTrigger = $('.has-submenu > a');
$menulink.click(function(e) {
e.preventDefault();
$menulink.toggleClass('active');
$menu.toggleClass('active');
@erickarbe
erickarbe / WooCommerce Price Next to Variation
Created January 15, 2018 15:59
Add the price next to the variation name on WooCommerce product
add_filter( 'woocommerce_variation_option_name', 'display_price_in_variation_option_name' );
function display_price_in_variation_option_name( $term ) {
global $wpdb, $product, $woocommerce;
if ( empty( $term ) ) return $term;
if ( empty( $product->get_id() ) ) return $term;
$result = $wpdb->get_col( "SELECT slug FROM {$wpdb->prefix}terms WHERE name = '$term'" );
@erickarbe
erickarbe / Matchlink.txt
Created July 1, 2020 13:40
Regular Expression to match a link
<?php
// Click to tweet functionality. Look for the username and hashtags at the end of the string.
$main_question = get_the_title();
$twitter_quote = get_field('twitter_quote');
?>
<div class="tweet-this">
<a class="click-tweet" href="http://twitter.com/share?text=<?php echo html_entity_decode($main_question); ?> &#34;<?php if($twitter_quote) { echo urlencode($twitter_quote); } ?>&#34; via <?php echo $fullname . ' ' . $twitter_handle; ?>&url=<?php echo $roundup_permalink; ?>&hashtags=backswing @getbackswing" target="_blank">
Click to Tweet
</a>