Skip to content

Instantly share code, notes, and snippets.

View Jany-M's full-sized avatar
🎯
Focusing

Jany Martelli Jany-M

🎯
Focusing
View GitHub Profile
@Jany-M
Jany-M / random_masonry.js
Last active November 14, 2019 16:14
Masonry image size randomizer (with PHP, LESS and isotope.js)
$('.grid').isotope({
itemSelector: '.grid-item',
//percentPosition: true,
masonry: {
columnWidth: 100
}
})
@Jany-M
Jany-M / wp_scripts.php
Created August 22, 2018 17:00
[WP] Add async, defer and origin attributes to WordPress scripts
<?php
// Place the handles somewhere convenient
global $scripts_to_defer, $scripts_to_async, $scripts_origin;
$scripts_to_defer = array('fancybox_js', 'bootstrap_js');
$scripts_to_async = array('fontawesome_js');
$scripts_origin = array('fontawesome_js');
// Put this in functions.php
function add_defer_attribute($tag, $handle) {
@Jany-M
Jany-M / woo_remove_product_tags.php
Created July 24, 2018 14:23
[WP][WC] Remove / Hide WooCommerce product tags, the right way
<?php
// Overwrite product_tag taxonomy properties
add_action('init', function() {
register_taxonomy('product_tag', 'product', [
//'public' => false, // making it not public could throw errors in some themes / plugins
'show_ui' => false,
'show_admin_column' => false,
'show_in_nav_menus' => false,
'show_tagcloud' => false,
@Jany-M
Jany-M / gdpr_scripts.php
Last active May 21, 2021 13:55
[GDPR] Scripts to ask / check for user consent (WordPress and JS examples)
<?php
/* --------------------------------------------------------------------------------
*
* JS stand-alone (CSS not included - Get it here https://pastebin.com/uNKPdMVj)
*
-------------------------------------------------------------------------------- */
?>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
@Jany-M
Jany-M / expires.conf
Last active January 27, 2020 13:10
[Apache] mod_expires conf
# etc/httpd/conf.d/expires.conf
# https://support.plesk.com/hc/en-us/articles/115001711985-How-to-enable-leverage-browser-caching-in-Plesk
# https://support.plesk.com/hc/en-us/articles/213380049-How-to-enable-gzip-compression-on-nginx-on-Plesk-server
LoadModule expires_module modules/mod_expires.so
ExpiresActive on
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType application/x-font-ttf "access plus 1 year"
@Jany-M
Jany-M / wc-custom_attributes.php
Created March 20, 2018 00:59
[WP][WooCommerce] Customize attributes & Edit "Variation Swatches" plugin
<?php
/* ------------------------------------------------------------------------------------------------
*
* METHOD 1
*
-------------------------------------------------------------------------------------------------- */
// Customize WooCommerce Attributes (method 1 - no swatches/plugins)
function wc_custom_attr( $product ) {
@Jany-M
Jany-M / wp_wc_filter_by_featured_product.php
Last active June 6, 2021 16:18
[WP][WooCommerce] Add featured products filter
@Jany-M
Jany-M / wp_get_og_img.php
Last active June 6, 2021 16:19
[WP] Get an image for Open Graph
<?php
// Get an image for Open Graph - Uses WP Imager https://github.com/Jany-M/WP-Imager
if(is_singular()) {
global $post;
if(function_exists('wp_imager')) {
$img = wp_imager(1200, 630, 1, '', '', '', true );
} elseif(has_post_thumbnail($post->ID)) {
$img = get_the_post_thumbnail_url( $post->ID, array(1200,630));
}
} else {
@Jany-M
Jany-M / wp_add_body_classes.php
Last active June 6, 2021 16:20
[WP] Add custom body classes for better CSS customization
<?php
function add_classes_to_body($classes) {
global $post;
// User Role
$user_info = get_currentuserinfo();
$classes[] = implode(' ', $user_info->roles);
// WPML
if ( function_exists('icl_object_id') ) {
@Jany-M
Jany-M / wp_rename_upload_files.php
Created April 19, 2017 22:50
[WP] Rename files in custom upload folder
<?php
/* ----------------------------------------------------------------------------------------------------------------------------
* PREFACE for this script
*
* A frontend custom form, allowing registered users to create a custom post type + upload images to ACF Gallery custom field,
* in a custom uploads folder, had a bug where it would replace any symbol with -,
* including replacing the file extensions (eg. .jpg and .png, in -jpg and -png).
* That resulted in various issues, even though browsers could still read the file as image.
* After fixing the form itself, this script was made, to fix all the uploads that had already been uploaded and their path.