Skip to content

Instantly share code, notes, and snippets.

View nicomollet's full-sized avatar

Nico Mollet nicomollet

View GitHub Profile
@nicomollet
nicomollet / gifticon.php
Last active July 25, 2017 13:04
Add gift icon the Shop menu item
<?php
/**
* Add gift icon the Shop menu item
*
* @param $sorted_menu_items
*
* @return mixed
*/
function gifticon_nav_menu_objects( $sorted_menu_items )
{
@nicomollet
nicomollet / homeicon.php
Created July 25, 2017 13:05
Replace Home menu item by home icon
<?php
/**
* Replace Home menu item by home icon
*
* @param $sorted_menu_items
*
* @return mixed
*/
function homeicon_nav_menu_objects( $sorted_menu_items )
{
@nicomollet
nicomollet / elementorcssinhead.php
Last active December 6, 2022 09:21
Load Elementor styles on all pages in the head to avoid CSS files being loaded in the footer
<?php
/**
* Load Elementor styles on all pages in the head to avoid CSS files being loaded in the footer
*/
function elementor_css_in_head(){
if(class_exists('\Elementor\Plugin')){
$elementor = \Elementor\Plugin::instance();
$elementor->frontend->enqueue_styles();
}
if(class_exists('\ElementorPro\Plugin')){
@nicomollet
nicomollet / polylang-display-post-states-language.php
Last active January 18, 2018 10:08
Polylang: Display a country flag or the name of the language as a "post state" in post lists
<?php
/**
* Polylang: Display a country flag or the name of the language as a "post state"
*
* @param array $post_states An array of post display states.
* @param \WP_Post $post The current post object.
*
* @return array A filtered array of post display states.
*/
function polylang_display_post_states_language( $post_states, $post ) {
@nicomollet
nicomollet / polylang-langswitcher-shortcode.php
Last active April 16, 2025 15:26
Polylang shortcode for lang switcher
<?php
/**
* Polylang Shortcode - https://wordpress.org/plugins/polylang/
* Add this code in your functions.php
* Put shortcode [polylang_langswitcher] to post/page for display flags
*
* @return string
*/
function custom_polylang_langswitcher() {
$output = '';
@nicomollet
nicomollet / email_order_items_product_description.php
Last active April 23, 2018 08:00
WooCommerce Order Email: Each Item with product description
<?php
add_action( 'woocommerce_order_item_meta_start', 'custom_order_email_product_description', 10, 4 );
function custom_order_email_product_description( $item_id, $item, $order, $plain_text = '' ){
$item_data = $item->get_data();
$product = wc_get_product($item_data['product_id'] );
$product_short_description = $product->get_short_description();
$product_description = $product->get_description();
if ( ! empty( $product_short_description ) ) {
@nicomollet
nicomollet / private_posts_search_resultats.php
Last active October 28, 2020 22:47
WordPress: display private posts in search results if user has permission
<?php
/**
* Search results: display private posts if user has permission
*
* @param WP_Query $query
*/
function custom_private_posts_earch_results( $query ) {
if ( current_user_can( 'read_private_posts' ) ) {
if ( $query->is_search() && $query->is_main_query() ) {
$query->set( 'post_status', [ 'publish', 'private' ] );
@nicomollet
nicomollet / woocommerce-price-multisite.php
Created April 23, 2018 08:06
WooCommerce Product Price Shortcode, compatible with multisite
<?php
/**
* WooCommerce Product Price Shortcode Compatible with Multisite
* Example: [woocommerce_price_multisite id="6452" site="6"]
*
* @param $atts
*
*/
function woocommerce_price_multisite( $atts ) {
@nicomollet
nicomollet / acf-disable-autocomplete.php
Created July 26, 2018 15:03
ACF Disable Autocomplete on input and textarea fields
<?php
/**
* ACF Disable Autocomplete on input and textarea fields
* Chrome ignores autocomplete="off" in some cases
*
* @author Nicolas Mollet
* @link https://bugs.chromium.org/p/chromium/issues/detail?id=468153
*/
function acf_input_disable_autocomplete() {
@nicomollet
nicomollet / gtm4wp-exclude-failed-orders.php
Created August 28, 2018 07:14
Google Tag Manager for WordPress (DuracellTomi): Exclude orders with status failed
<?php
/**
* Google Tag Manager: Exclude orders with status failed (only paid statuses)
*
* @param $tag
*
* @return string
*/
function googletagmanager_getthetag( $tag ) {
global $wp;