Skip to content

Instantly share code, notes, and snippets.

@crazyyy
crazyyy / _readme.md
Last active August 22, 2024 18:17
PageSpeed Lighthouse
@Neshable
Neshable / wp-common.conf
Created January 4, 2022 10:30
Nginx configuration file to be included with WordPress. Covers all major cases for 2021.
# WordPress COMMON SETTINGS - WordOps 3.13.2
# DO NOT MODIFY, ALL CHANGES WILL BE LOST AFTER AN WordOps (wo) UPDATE
# Limit access to avoid brute force attack
#Yoast SEO Sitemaps
location ~ ([^/]*)sitemap(.*).x(m|s)l$ {
## this rewrites sitemap.xml to /sitemap_index.xml
rewrite ^/sitemap.xml$ /sitemap_index.xml permanent;
## this makes the XML sitemaps work
rewrite ^/([a-z]+)?-?sitemap.xsl$ /index.php?yoast-sitemap-xsl=$1 last;
@alvarodelera
alvarodelera / functions.php
Created December 16, 2021 15:04
Copy excerpt in YoastSEO meta description if not empty
function copyExcerptInMetaDesc(){
$posts = get_posts(array(
'numberposts' => -1,
'fields' => 'ids',
'post_type' => array('post')
));
foreach( $posts as $postId ){
if(!get_post_meta( $postId, '_yoast_wpseo_metadesc', false )){
$excerpt = get_the_excerpt($postId);
@kyletaylored
kyletaylored / pantheon-sql-perf.php
Last active November 17, 2024 22:56
Fix SQL_CALC_FOUND_ROWS performance degradation on WordPress, fix database indexes and primary keys.
<?php
/**
* Plugin Name: WordPress SQL Performance
* Plugin URI: https://www.pantheon.io
* Description: Fix SQL_CALC_FOUND_ROWS performance degradation.
* Author: Kyle Taylor, Pantheon
* Version: 1.0
* License: GPL2
* Credit: https://wpartisan.me/tutorials/wordpress-database-queries-speed-sql_calc_found_rows
@Danushka181
Danushka181 / woocommerce-functions.php
Created November 30, 2021 19:05
woocommerce functions hooks
<?php
/**
* WooCommerce Template
*
* Functions for the templating system.
*
* @package WooCommerce\Functions
* @version 2.5.0
*/
@trey8611
trey8611 / find-woocommerce-attributes-by-name.md
Last active April 17, 2024 17:24
[Find WooCommerce Attributes by Name] Search by name instead of slug only. #wpallimport #woocommerce

Find attributes by name.

function my_find_attribute_by_name( $name, $attribute ) {
    global $wpdb;
    $term_table = $wpdb->prefix . 'terms';
    $taxonomy_table = $wpdb->prefix . 'term_taxonomy';

    if ( ! empty( $name ) ) {
@Treast
Treast / _fonts.scss
Created November 26, 2021 08:40
WordPress snippets
$fontPath: '../../fonts';
@mixin fonts($name, $file, $fontWeight) {
@font-face {
font-family: $name;
src: url('#{$fontPath}/#{to-lower-case(#{$name})}/#{$file}.eot');
src: url('#{$fontPath}/#{to-lower-case(#{$name})}/#{$file}.eot?#iefix') format('embedded-opentype'),
url('#{$fontPath}/#{to-lower-case(#{$name})}/#{$file}.woff2') format('woff2'),
url('#{$fontPath}/#{to-lower-case(#{$name})}/#{$file}.woff') format('woff'),
url('#{$fontPath}/#{to-lower-case(#{$name})}/#{$file}.ttf') format('truetype'),
@trey8611
trey8611 / custom-log-functions.md
Created November 19, 2021 16:28
[WP All Import] Custom log / custom logging functions with our API

This shows how to save a custom log of imported items. It can be adjusted to include any product data.

  /***********************************************/
 /***** BEGIN LOG CREATE / UPDATE / DELETE  *****/
/********************************************* */

// This creates a custom log file in the root WordPress uploads folder
// Some of this code will need to be adjusted, please read comments.
@Shoora
Shoora / ga4.php
Created November 17, 2021 14:06 — forked from rmpel/ga4.php
GA4 Tracker mu-plugin
<?php // wp-content/mu-plugins/ga4.php - GA4 tracker boilerplate.
define('GA_NOT_LIVE', true); // remove for go
define('GA4_MEASUREMENT_ID', 'G-XXXXXXXXXX'); // required
define('UA_PROPERTY_ID', 'UA-XXXXXXX-YY'); // optional
define('GA_ANONYMIZE_IP', true); // optional
define('GA_TRACK_ADMINS', false); // optional, defaults to true
define('GA_TRACK_EDITORS', false); // optional, defaults to true
// we need GA as first thing in the body
@alfonmga
alfonmga / ga4mp.js
Created November 11, 2021 20:04
GA4 measurement protocol JS lib
const axios = require('axios')
// This is the interface/object for communicating with GA4MP
export function GA4MPClient(apiSecret, measurementId, clientId) {
// Vars for GA4 connection
this.API_SECRET = apiSecret; // GA > Admin > Data Streams > choose your stream > Measurement Protocol > Create
this.MEASUREMENT_ID = measurementId; // GA Admin > Data Streams > choose your stream > Measurement ID