Skip to content

Instantly share code, notes, and snippets.

@amielucha
amielucha / gravity-euro-sign.php
Created August 5, 2016 11:58
WordPress Gravity forms - position € sign
<?php
// place in functions.php
add_filter( 'gform_currencies', 'update_currency' );
function update_currency( $currencies ) {
$currencies['EUR'] = array(
'name' => __( 'Euro', 'gravityforms' ),
'symbol_left' => '&#8364;',
'symbol_right' => '',
'symbol_padding' => ' ',
@amielucha
amielucha / wp-query-uses.php
Last active November 2, 2018 16:55
WP_Query() usage examples - WordPress custom post types (keywords: query, loop)
<?php
/*
* Display 4 items from Member post type.
* Posts are organized by menu order.
* Use https://wordpress.org/plugins/simple-page-ordering/ or similar to easily sort items.
*/
$the_query = new WP_Query( array(
'post_type' => 'member',
'posts_per_page' => 4,
@amielucha
amielucha / mobile-nav.scss
Created November 3, 2016 14:12
Fullscreen mobile navigation for Lightseek theme
// Use with Lightseek theme in style.css
.nav-menu-container {
.navbar-nav {
width: 100%;
// Mobile menu
@include media-breakpoint-down(sm) {
align-items: center;
background: darken(rgba($brand-primary, .9), 10%);
@amielucha
amielucha / scrollTo.js
Created December 5, 2016 12:53
Scroll To Hash with jQuery
// First enqueue this funciton in functions.php
`wp_enqueue_script( 'scrollto', '//cdn.jsdelivr.net/jquery.scrollto/2.1.2/jquery.scrollTo.min.js', array( 'jquery' ), '20161205', true );`
// Bind to the click of all links with a #hash in the href
if ( $.isFunction($.fn.scrollTo) ) {
$('a[href^="#"]').click(function(e) {
e.preventDefault();
// Scroll the window, stop any previous animation, stop on user manual scroll
// Check https://github.com/flesler/jquery.scrollTo for more customizability
$(window).stop(true).scrollTo(this.hash, {duration:1000, interrupt:true});
@amielucha
amielucha / functions.php
Created January 24, 2017 15:49 — forked from fuyuko/functions.php
Cheatsheet - WooCommerce Customization in functions.php
<?php
//Add a stylesheet after default style.css
wp_enqueue_style( 'my-css', get_template_directory_uri() . 'my-css.css', array('themename-style'));
//WooCommerce - Sort products by SKU
add_filter('woocommerce_get_catalog_ordering_args', 'custom_woocommerce_catalog_orderby');
function custom_woocommerce_catalog_orderby( $args ) {
$args['meta_key'] = '_sku';
$args['orderby'] = 'meta_value';
$args['order'] = 'asc';
@amielucha
amielucha / toolset_types_disable_url_validation.php
Created February 5, 2017 18:31
Disable Toolset WP Types URL validation in the backend
<?php
/*
* Issue: the validation was preventing me from using non-standard domains when developing on localhost.
* Solution: disabled the URL verification, so I can use relative URLs and non-standard domains.
*
*/
/*
* Disable admin URL validation for Files, Images, Audio, and Video.
@amielucha
amielucha / .htaccess
Created March 9, 2017 16:07
WordPress force SSL .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
@amielucha
amielucha / free-ebooks.sh
Created March 20, 2017 11:17
Free O'Reilly ebooks
wget http://www.oreilly.com/programming/free/files/modern-java-ee-design-patterns.epub
wget http://www.oreilly.com/programming/free/files/object-oriented-vs-functional-programming.epub
wget http://www.oreilly.com/programming/free/files/java-the-legend.epub
wget http://www.oreilly.com/programming/free/files/introducing-java-8.epub
wget http://www.oreilly.com/programming/free/files/a-whirlwind-tour-of-python.epub
wget http://www.oreilly.com/programming/free/files/20-python-libraries-you-arent-using-but-should.epub
wget http://www.oreilly.com/programming/free/files/hadoop-with-python.epub
wget http://www.oreilly.com/programming/free/files/how-to-make-mistakes-in-python.epub
wget http://www.oreilly.com/programming/free/files/functional-programming-python.epub
wget http://www.oreilly.com/programming/free/files/python-in-education.epub
@amielucha
amielucha / functions-sort-prev-next-by-menu-order.php
Created September 12, 2017 11:12
WordPress: sort Previous and Next post by menu_order
<?php
function my_previous_post_where() {
global $post, $wpdb;
return $wpdb->prepare( "WHERE p.menu_order < %s AND p.post_type = %s AND p.post_status = 'publish'", $post->menu_order, $post->post_type);
}
add_filter( 'get_previous_post_where', 'my_previous_post_where' );
function my_next_post_where() {
global $post, $wpdb;
return $wpdb->prepare( "WHERE p.menu_order > %s AND p.post_type = %s AND p.post_status = 'publish'", $post->menu_order, $post->post_type);
}
@amielucha
amielucha / acf-pro-filter-add-tabs-to-content.php
Created October 27, 2017 10:50
ACF PRO - WordPress - render repeated as tabs
<?php
/*
* Append Bootstrap tabs to the post's content using ACF Pro repeater field.
*
* Prequisites:
* - ACF PRO plugin
* - Repeater field `tabs` containing `tab_title` (text) and `tab_content` (WYSIWYG) fields.
* - Bootstrap 4.0 with util.js and tab.js loaded (or bootrap.js)
*/