Skip to content

Instantly share code, notes, and snippets.

@Sanabria
Sanabria / functions.php
Created January 12, 2021 03:54 — forked from aliboy08/functions.php
Woocommerce - Single Product Carousel
// Modify single product images: add carousel functionality
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
add_action( 'woocommerce_before_single_product_summary', function(){
global $product;
$image_ids = [];
// featured image
if( has_post_thumbnail() ) $image_ids[] = get_post_thumbnail_id();
@Sanabria
Sanabria / sage-google-fonts-config.php
Created April 10, 2020 22:37 — forked from briankompanee/sage-google-fonts-config.php
WordPress: Add Google Font support to the Sage theme for roots.io
<?php
/**
* Add your Google Fonts here.
* This is specifically for the theme Sage from roots.io and goes in config.php
* Change the font name, weights and styles to what you are using as needed.
*/
define('GOOGLE_FONTS', 'Oswald:400,300,700:latin');
@Sanabria
Sanabria / largest-tables-in-mysql-database.sql
Created November 13, 2019 22:52 — forked from Kevinlearynet/largest-tables-in-mysql-database.sql
Find the largest (sized by MB) tables in your MySQL database. Especially useful for diagnosing and fixing a bloated WordPress database.
# Find the largest tables in your MySQL database
SELECT
table_name as "Table",
table_rows as "Rows",
data_length as "Length",
index_length as "Index",
round(((data_length + index_length) / 1024 / 1024),2) as "Size (mb)"
FROM information_schema.TABLES
WHERE table_schema = "%%YOURDATABASE%%"
ORDER BY `Size (mb)` DESC
@Sanabria
Sanabria / custom-excerpt.php
Created February 25, 2019 16:05
Custom excerpt
function custom_read_more() {
return '... <a class="read-more" href="'.get_permalink(get_the_ID()).'">more&nbsp;&raquo;</a>';
}
function excerpt($limit) {
return wp_trim_words(get_the_excerpt(), $limit, custom_read_more());
}
@Sanabria
Sanabria / gist:f9215385d190762dc72607b032d23873
Last active January 23, 2019 13:41
Add sublime to bash profile
add one line alias into your .bash_profile, then you are done:
alias subl='/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl'
use:
subl [YOUR_FILE_PATH_TO_OPEN]
@Sanabria
Sanabria / fade.js
Created January 16, 2019 15:34 — forked from alirezas/fade.js
fadeIn & fadeOut in vanilla js
function fadeOut(el){
el.style.opacity = 1;
(function fade() {
if ((el.style.opacity -= .1) < 0) {
el.style.display = "none";
} else {
requestAnimationFrame(fade);
}
})();
@Sanabria
Sanabria / .gitignore
Created October 29, 2018 03:18 — forked from salcode/.gitignore
Please see https://salferrarello.com/wordpress-gitignore/ for the canonical version of this WordPress .gitignore file. Note: I do not receive notifications for comments here (because GitHub does not send notifications on Gists)
# -----------------------------------------------------------------
# .gitignore for WordPress @salcode
# ver 20180808
#
# From the root of your project run
# curl -O https://gist.githubusercontent.com/salcode/b515f520d3f8207ecd04/raw/.gitignore
# to download this file
#
# By default all files are ignored. You'll need to whitelist
# any mu-plugins, plugins, or themes you want to include in the repo.
@Sanabria
Sanabria / Blade Version
Created August 1, 2018 00:22
Get Excerpt from an Advanced Custom Field ACF
function custom_field_excerpt($text, $words) {
global $post;
//$text = get_field('your_field_name'); //Replace 'your_field_name'
if ( '' != $text ) {
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]&gt;', ']]&gt;', $text);
$excerpt_length = $words; // 20 words
$excerpt_more = apply_filters('excerpt_more', ' foobar' . '[...]');
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
/**
* Bulma Tabs Walker Subnav
*/
add_filter('nav_menu_css_class' , __NAMESPACE__ .'\special_nav_class' , 10 , 2);
function special_nav_class($classes, $item){
if( in_array('current-menu-item', $classes) ){
$classes[] = 'is-active ';
}
return $classes;
}
@Sanabria
Sanabria / filters.php
Created June 11, 2018 20:17
include ACF into Sage 9
/**
* Customize ACF path
*/
add_filter('acf/settings/path', function ( $path ) {
$path = get_stylesheet_directory() . '/../vendor/advanced-custom-fields/advanced-custom-fields-pro/';
return $path;
});