Skip to content

Instantly share code, notes, and snippets.

@luizlopescom
luizlopescom / js_get_utm_values.js
Created September 14, 2020 23:14
Get UTM Values via javascript
//GET UTM VALUES
//get url
var urlQueryString = window.location.search;
//set params
var urlParams = new URLSearchParams(urlQueryString);
//set vars to empty to avoid receiving 'NULL' on forms
var utm_source = ' ';
@luizlopescom
luizlopescom / Autoptimize hooks
Created September 12, 2020 22:03
List of WP Autoptimize plugin hooks
//Change AO folder and file prefix
//It's mandatory to have an underline
//serve files from e.g. /wp-content/resources/aggregated_12345.css
//wp_config.php
define('AUTOPTIMIZE_CACHE_CHILD_DIR','/resources/');
define('AUTOPTIMIZE_CACHEFILE_PREFIX','aggregated_');
//Enable non-ASCII characters
add_filter('autoptimize_filter_main_use_mbstring', '__return_true');
<?php
/**
* Add useful shortcodes
*
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
@luizlopescom
luizlopescom / .htaccess
Last active August 31, 2020 07:59 — forked from Ollo/.htaccess
Expire headers .htaccess code.
<IfModule mod_expires.c>
ExpiresActive on
# Perhaps better to whitelist expires rules? Perhaps.
ExpiresDefault "access plus 1 month"
# Data
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
# Favicon (cannot be renamed)
ExpiresByType image/x-icon "access plus 1 week"
//Remove Dashicons for not logged in users
add_action( 'wp_print_styles', 'dashicons_dequeue_styles' );
function dashicons_dequeue_styles() {
if ( ! is_user_logged_in() ) {
wp_dequeue_style( 'dashicons' );
wp_deregister_style( 'dashicons' );
}
}
@luizlopescom
luizlopescom / wp change order archive.php
Last active June 1, 2020 20:50
WordPress Archive.php - change sort order
// Display Fornecedores & Produtos in ASC order by title
function my_change_sort_order($query){
if(is_archive()): //If you wanted it for the archive of a custom post type use: is_post_type_archive( $post_type )
//if (is_post_type_archive( 'fornecedores' ) | is_post_type_archive( 'produtos' ) ):
//Set the order ASC or DESC
$query->set( 'order', 'ASC' );
//Set the orderby
$query->set( 'orderby', 'title' );
endif;
};
@luizlopescom
luizlopescom / Archive.php include cpt
Last active June 1, 2020 20:48
WordPress Archive - include/display custom post type in archive.php results
// Archive.php only shows content of type 'post'
// This filter include custom post type
function archive_add_custom_post_types( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array(
'post', 'fornecedores', 'produtos' //fornecedores ad produtos are custom post types
));
return $query;
}
}
<?php
/**
* Add security and performance enhancements
*
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
// remove version from head
/**
* Randomize widgets in a given sidebar (index) and only display a single widget
*
* @See http://wordpress.stackexchange.com/a/152408/26350
*
* Good for Ad banners (simple)
*
*/
! is_admin() && add_filter( 'sidebars_widgets', function( $sidebars_widgets ) {
// ------------------------