Skip to content

Instantly share code, notes, and snippets.

@huytrq
huytrq / functions1a.php
Created August 25, 2023 04:36 — forked from agusmu/functions1a.php
Customize WooCommerce Categories & Tags Label
/* Customize Product Categories Labels */
add_filter( 'woocommerce_taxonomy_args_product_cat', 'custom_wc_taxonomy_args_product_cat' );
function custom_wc_taxonomy_args_product_cat( $args ) {
$args['label'] = __( 'Product Categories', 'woocommerce' );
$args['labels'] = array(
'name' => __( 'Product Categories', 'woocommerce' ),
'singular_name' => __( 'Product Category', 'woocommerce' ),
'menu_name' => _x( 'Categories', 'Admin menu name', 'woocommerce' ),
'search_items' => __( 'Search Product Categories', 'woocommerce' ),
'all_items' => __( 'All Product Categories', 'woocommerce' ),
@huytrq
huytrq / WP_Query.php
Created April 29, 2022 09:23 — forked from Dimasmagadan/WP_Query.php
#WordPress query with args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
*/
$args = array(
//////Author Parameters - Show posts associated with certain author.
@huytrq
huytrq / .htaccess
Created March 4, 2021 02:44
Prevent a specific PDF file from being indexed by search engines in Wordpress
# The <Files> directive only applies to filenames, not file-paths, so your <Files> directive will never match and the header will not be set.
# To set this header on a specific file (and not all .pdf files - as in the linked question/answers) in the root .htaccess file then you can set an environment variable when this file is requested and conditionally set the header based on this env var.
# For example:
SetEnvIf Request_URI "/path/to/example.pdf" NOINDEX
Header set X-Robots-Tag "noindex, nofollow" env=NOINDEX
# Alternatively, if you could place an additional .htaccess file in the directory that contains the PDF file you want to target, then you could use a <Files> directive in that .htaccess file:
@huytrq
huytrq / autoptimize_defer_inline_jquery.php
Created January 31, 2021 14:30 — forked from futtta/autoptimize_defer_inline_jquery.php
POC to defer inline JS that requires jQuery
<?php
add_action('plugins_loaded','ao_defer_inline_init');
function ao_defer_inline_init() {
if ( get_option('autoptimize_js_include_inline') != 'on' ) {
add_filter('autoptimize_html_after_minify','ao_defer_inline_jquery',10,1);
}
}
function ao_defer_inline_jquery( $in ) {
@huytrq
huytrq / element-name.php
Created January 30, 2021 11:40
Visual Composer custom module
<?php
/*
* Element Description: VC Custom Element
*/
// Element Class
class vcCustomElement {
// Element Init
function __construct() {
@huytrq
huytrq / gsap-properties-cheat-sheet.md
Created August 13, 2020 10:28 — forked from lunelson/gsap-properties-cheat-sheet.md
Greensock Properties Cheat Sheet

Greensock CSS properties Cheat Sheet

I wrote this as a reference for myself because some of the property names are non-obvious, and there are a number of relevant special properties, and there is no central concise listing of them all in GSAP Docs, other than (in longer form) on the CSSPlugin page.

Standard CSS properties

...are all supported, with hyphenated-names becoming camelCaseNames. Non-animatable properties are also supported but they will be set at the beginning of the tween.

Special mentions:

@huytrq
huytrq / function.php
Created August 19, 2019 13:53
Add lazyload to image and iframe
<?php
function ht_add_lazy_loading($content) {
$content = preg_replace('/src="/', loading="lazy" src="', $content);
return $content;
}
add_filter('the_content', ht_add_lazy_loading);
?>
@huytrq
huytrq / woo-image-sizes.php
Created October 31, 2018 03:17
Adding Images in WooCommerce
/**
* Change your catalog images with a specific size
**/
add_filter( 'woocommerce_get_image_size_thumbnail', 'ci_theme_override_woocommerce_image_size_thumbnail' );
function ci_theme_override_woocommerce_image_size_thumbnail( $size ) {
// Catalog images: specific size
return array(
'width' => 750,
'height' => 430,
'crop' => 1,
@huytrq
huytrq / update-cart-ajax.php
Created June 21, 2018 10:44
Update Custom Cart Count (or any HTML) after AJAX Add to Cart in WooCommerce
<?php add_filter( 'woocommerce_add_to_cart_fragments', 'iconic_cart_count_fragments', 10, 1 );
function iconic_cart_count_fragments( $fragments ) {
$fragments['div.header-cart-count'] = '<div class="header-cart-count">' . WC()->cart->get_cart_contents_count() . '</div>';
return $fragments;
}
?>
@huytrq
huytrq / gallery.php
Created April 2, 2018 10:11 — forked from kokers/gallery.php
ACF Pagination Gallery with categories