Skip to content

Instantly share code, notes, and snippets.

View IacopoC's full-sized avatar
🎯
Crunch mode

Iacopo C IacopoC

🎯
Crunch mode
View GitHub Profile
@IacopoC
IacopoC / trash-wp.php
Last active January 19, 2017 14:16
Trash time constant in WordPress
<?php define('EMPTY_TRASH_DAYS', 30); ?>
@IacopoC
IacopoC / woocommerce_check_cart_items_hook
Created March 4, 2017 13:17
WooCommerce hook that checks number of items in the cart
<?php do_action( 'woocommerce_check_cart_items' ); ?>
<?php
// return true if we are in the cart page
is_cart();
// return true if we are in the checkout page
is_checkout();
@IacopoC
IacopoC / enqueue-css.php
Created April 15, 2017 19:32
Enqueue Css in WordPress plugin
/**
* Enqueue css
**/
function load_custom_wp_admin_style() {
wp_register_style( 'style.css', plugins_url('/css/style.css', __FILE__), false, '1.0.0' );
wp_enqueue_style( 'style.css' );
}
add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );
@IacopoC
IacopoC / ga-tracking-wp.php
Last active April 18, 2017 10:02
Google analytics tracking code snippet in functions.php WordPress
<?php add_action('wp_head', 'add_google_analytics');
function add_google_analytics() {
// Insert your GA code here
}
<?php
// enqueue font awersome from local css folder
function enqueue_fontawersome_stylesheets(){
wp_enqueue_style('font-awesome', get_stylesheet_directory_uri() . '/css/font-awesome.css');
}
add_action('wp_enqueue_scripts','enqueue_fontawersome_stylesheets');
@IacopoC
IacopoC / check-language-wpml.php
Created June 20, 2017 11:32
Check which language are you visualizing in wpml and do some actions
<?php if(ICL_LANGUAGE_CODE=='en'):
// do something
elseif(ICL_LANGUAGE_CODE=='it'):
// do something else
endif; ?>
@IacopoC
IacopoC / Wc add notice for errors
Created March 4, 2017 13:25
Function useful to display error notice in WooCommerce
<?php
// Wc add notice can be used to create error, notice or success messages in WooCommerce. In this case we see error notice.
wc_add_notice( $message, $notice_type = 'error' );
@IacopoC
IacopoC / custom-qorder.php
Created November 20, 2017 10:47
Order custom query by last word
<?php
$args = [
'posts_per_page' => 10,
'post_type' => 'speaker',
'meta_key' => 'speaker-front-page',
'meta_value' => '1',
'orderby' => 'customq_last_word', //<-- Custom ordering
'order' => 'ASC'
];
@IacopoC
IacopoC / Allow-cpt-in-category-list-archive.php
Last active November 23, 2017 12:07
Allow cpt in category list archive in wordpress
<?php
// Allow cpt in category list
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if( is_category() ) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('nav_menu_item', 'post', 'name_of_post_type'); // don't forget nav_menu_item to allow menus to work!