Skip to content

Instantly share code, notes, and snippets.


Jany Martelli Jany-M

View GitHub Profile
Jany-M / wp_include_terms_in_search_wpml_compatible.php
Last active Jun 6, 2021
[WP] Include terms in WordPress standard search results + WPML compatibility
View wp_include_terms_in_search_wpml_compatible.php
function custom_search_where($where){
global $wpdb;
if (is_search() && get_search_query())
$where .= "OR (( LIKE '%".get_search_query()."%' OR t.slug LIKE '%".get_search_query()."%') AND {$wpdb->posts}.post_status = 'publish')";
if (function_exists('icl_get_languages')) {
Jany-M /
Created Mar 17, 2020 — forked from holmberd/
Adjusting child processes for PHP-FPM (Nginx)
Jany-M / wc_dynamic_saleprice.php
Last active Jun 6, 2021
[WP][WooCommerce] Calculate sale price dynamically / programmatically based on taxonomy term custom field % (also works for Facebook Catalog feed)
View wc_dynamic_saleprice.php
// The discount is set through a term meta 'sale_value' associated to the product, so that product regular or sales prices never need to changed manually
// The script also assumes the use of ACF, through get_field()
// BACKEND (Product list, FB feed)
function custom_dynamic_sale_price( $sale_price, $product ) {
$id = $product->get_id();
$tax = get_the_terms($id,'product_cat');
$regular_price = wc_format_decimal( $product->get_price() );
Jany-M / google_map_api3_multiple_locations_infowindow_with_html_gallery.js
Last active Feb 17, 2020
Google Maps API3 - Multiple markers and Infowindow with custom content and gallery, using Geocode
View google_map_api3_multiple_locations_infowindow_with_html_gallery.js
Jany-M / remove_admin_menu_items.php
Created Dec 17, 2019
[WP] Edit WordPress admin menu (backend) - Remove items/pages and sub-items/sub-pages, including Customizer
View remove_admin_menu_items.php
// Remove items from menu for Editors
function remove_admin_menu_items() {
if(current_user_can('editor') && !current_user_can('administrator')) {
// Remove menu items
// Tools
remove_menu_page( 'tools.php' );
Jany-M / mu_loop.php
Last active Jan 19, 2022
[WP MU] Shortcode for custom loops between different blogs - For WordPress Multisite MU
View mu_loop.php
// This is a work in progress, but it works fine
// Requires custom functions & libraries not present in the script (eg. Swiper)
// Adapted from my Visual Composer custom module (same purpose)
// Doesn't play well with WPML, for now
function shambix_shortcode_mu_posts($atts, $content = null ) {
// Let's compare parameters with defaults
Jany-M / vc-mu_loop.php
Last active Apr 10, 2021
[WP] Visual Composer custom query loop block / module, for WordPress Multisite
View vc-mu_loop.php
// There's also a standalone version, no Visual Composer required, purely as a shortcode here
if( class_exists( 'WPBakeryShortCode' ) && !class_exists( 'vcMUloop' ) ) {
class vcMUloop extends WPBakeryShortCode {
function __construct() {
add_action( 'init', array( $this, 'vc_multisite_mapping' ) );
Jany-M / woocommerce_custom.php
Last active Jun 6, 2021
[WP][WooCommerce] Add SKU next to Variation ID in Admin Metabox
View woocommerce_custom.php
// Add SKU next to variation ID
function display_sku_next_to_var_ids() {
<script type="text/javascript">
jQuery(function($) {
"use strict";
$(document).on('woocommerce_variations_loaded', function(event) {
var id = -1;
$('.woocommerce_variation.wc-metabox').each( function(index, elem) {
Jany-M / manage_paragraphs.php
Last active Nov 26, 2019
[WP][PHP] Split first paragraph from main content, display it elsewhere
View manage_paragraphs.php
// Grab the first paragraph, show it where you need it, then take the rest of the content and remove the first paragraph and show it elsewhere
// The script uses WordPress functions/content but can be used in any PHP script, just replace the WP functions
// First Paragraph
global $post;
$p1 = wpautop( $post->post_content );
$p1 = substr( $p1, 0, strpos( $p1, '</p>' ) + 4 );
//$p1 = strip_tags($p1, '<a><strong><em><h3><h2><i>'); // in case you need to remove some tags, add the ones you want to KEEP here
Jany-M / random_masonry.js
Last active Nov 14, 2019
Masonry image size randomizer (with PHP, LESS and isotope.js)
View random_masonry.js
itemSelector: '.grid-item',
//percentPosition: true,
masonry: {
columnWidth: 100