Skip to content

Instantly share code, notes, and snippets.

View chrdesigner's full-sized avatar

César Ribeiro chrdesigner

View GitHub Profile
@chrdesigner
chrdesigner / .htaccess
Created December 21, 2023 15:13
htaccess redirect www to non-www
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
</IfModule>
@chrdesigner
chrdesigner / functions.php
Created November 17, 2022 14:21
Use GD instead of Imagick.
<?php
/** * Use GD instead of Imagick.
*/
function chr_use_gd_editor($array) {
return array( 'WP_Image_Editor_GD' );
}
add_filter( 'wp_image_editors', 'chr_use_gd_editor' );
@chrdesigner
chrdesigner / main.js
Created December 10, 2015 01:11
Script for reload only different Browser Width
//Create the VAR for get browser size
var windowWidth = $(window).width();
$(window).bind('resize', function(e) {
//Verification with my VAR windowWidth is different Window size
if(windowWidth != $(window).width()){
//Create a delay for reload
if (window.RT) clearTimeout(window.RT); window.RT = setTimeout(function() {
this.location.reload(false);
}, 200);
@chrdesigner
chrdesigner / functions.php
Created August 27, 2014 19:16
Custom Add To Cart Messages
<?php
add_filter( 'wc_add_to_cart_message', 'custom_add_to_cart_message' );
function custom_add_to_cart_message( $product_id ) {
$product_id = $_REQUEST[ 'product_id' ];
if ( is_array( $product_id ) ) {
$titles = array();
@chrdesigner
chrdesigner / filter-external.js
Created September 17, 2018 19:21
Sub Menu + Filter TAG ~ External
$('.filterBlog a').on('click', function(e) {
filterBlogHash(this.hash, e);
});
$(window).on('load',function() {
filterBlogHash(window.location.hash);
});
function filterBlogHash(hash, e) {
if(hash === '') {
@chrdesigner
chrdesigner / filter.js
Created September 17, 2018 19:20
Sub Menu + Filter TAG ~ Simple
$('.filterBlog').on('click', 'a', function(e){
e.preventDefault();
var hash = $(this).attr('href').replace(/^.*?(#|$)/,'');
$('.filter a.type').each(function (index, value) {
// console.log('filter' + index + ':' + $(this).attr('id'));
@chrdesigner
chrdesigner / functions.php
Last active July 30, 2018 20:52
Vender Somente para Estado Específico - WooCommerce
<?php
/**
* Brazillian states
* Function - Vender Somente para Estados Específicos - WooCommerce
*/
function wc_especifico_estado( $states ) {
$states['BR'] = array(
'SP' => __( 'S&atilde;o Paulo', 'woocommerce' ),
'RJ' => __( 'Rio de Janeiro', 'woocommerce' ),
);
@chrdesigner
chrdesigner / functions.php
Last active November 9, 2017 12:08
Function to create a custom related post list by tag and category
<?php
/**
* Related Posts.
*
* Usage:
* To show related by categories:
* Add in single.php <?php chr_related_posts(); ?>
* To show related by tags:
* Add in single.php <?php chr_related_posts( 'tag' ); ?>
*
@chrdesigner
chrdesigner / functions.php
Last active November 3, 2017 01:21
Display Groups of Custom Posts by their Custom Taxonomy Term
<?php
$post_type = 'post';
// Get all the taxonomies for this post type
$taxonomies = get_object_taxonomies( (object) array( 'post_type' => $post_type ) );
foreach( $taxonomies as $taxonomy ) :
// Gets every "category" (term) in this taxonomy to get the respective posts
$terms = get_terms( $taxonomy,
@chrdesigner
chrdesigner / main.js
Last active September 14, 2017 21:12
Máscara em jQuery para o oite e nove dígitos
// <![CDATA[
jQuery(function($) {
$.mask.definitions['~']='[+-]';
//Inicio Mascara Telefone
$('input[type=tel]').focusout(function(){
var phone, element;
element = $(this);
element.unmask();
phone = element.val().replace(/\D/g, '');
if(phone.length > 10) {