Skip to content

Instantly share code, notes, and snippets.

@tcrsavage
tcrsavage / gist:6017245
Created July 17, 2013 02:36
Default the_post_thumbnail() and get_the_post_thumbnail() to return the first image in post content if no featured image is set
//If no post thumbnail exists, get the first image in the post and return that instead
add_filter( 'post_thumbnail_html', function( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
if ( $html )
return $html;
$found = preg_match( '/<img.+?class=\".+?([0-9]+).*\/>/', get_post( $post_id )->post_content, $matches );
if ( $found )
$html = wp_get_attachment_image( end( $matches ), $size, false, $attr );
@MikeNGarrett
MikeNGarrett / wp-config.php
Last active November 7, 2024 08:58
All those damned wp-config constants you can never remember.
<?php
// PHP memory limit for this site
define( 'WP_MEMORY_LIMIT', '128M' );
define( 'WP_MAX_MEMORY_LIMIT', '256M' ); // Increase admin-side memory limit.
// Database
define( 'WP_ALLOW_REPAIR', true ); // Allow WordPress to automatically repair your database.
define( 'DO_NOT_UPGRADE_GLOBAL_TABLES', true ); // Don't make database upgrades on global tables (like users)
// Explicitely setting url
@devdrops
devdrops / example.md
Last active July 23, 2024 14:20
Mysqldump from Docker container

Mysqldump from Docker container

docker exec -i mysql_container mysqldump -uroot -proot --databases database_name --skip-comments > /path/to/my/dump.sql

OBS

  • This will generate a dump.sql file in your host machine. Awesome, eh?
  • Avoid using --compact on your dump. This will make MySQL check your constraints which will cause troubles when reading your file (damm you MySQL). And don't use --force to fix this scenario: recreate your dump without --compact ¯_(ツ)_/¯
@isaactzab
isaactzab / optimizations-for-prestashop-1.6.md
Last active January 18, 2023 22:49
Prestashop tips and tricks

Optimizations and enhancements for prestashop 1.6

Sometimes, prestashop turns very slow due to ads, and module recomendations. Here are some modifications to version 1.6 removing these things and speed up the admin panels. Enjoy and share your tricks about how optimize prestashop.

Modify Tools class

[https://github.com/PrestaShop/PrestaShop/blob/1.6.1.x/classes/Tools.php#L3351-L3356] Find the file /public/classes/Tools.php and modify as next:

public static function addonsRequest($request, $params = array())
@shrop
shrop / curl-loop.sh
Created March 31, 2017 14:12
Script to loop through a text file list of URLs and output the curl -I to a text file
#!/bin/bash
for i in $(cat urls.txt); do
content=$(curl -I -s "{$i}")
echo "URL: $i" >> output.txt
echo "$content" >> output.txt
done
@lukecav
lukecav / Query
Last active July 11, 2024 16:45
MySQL script to get all WooCommerce orders including metadata
select
p.ID as order_id,
p.post_date,
max( CASE WHEN pm.meta_key = '_billing_email' and p.ID = pm.post_id THEN pm.meta_value END ) as billing_email,
max( CASE WHEN pm.meta_key = '_billing_first_name' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_first_name,
max( CASE WHEN pm.meta_key = '_billing_last_name' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_last_name,
max( CASE WHEN pm.meta_key = '_billing_address_1' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_address_1,
max( CASE WHEN pm.meta_key = '_billing_address_2' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_address_2,
max( CASE WHEN pm.meta_key = '_billing_city' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_city,
max( CASE WHEN pm.meta_key = '_billing_state' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_state,
#!/bin/bash
# CACHE WARMER script for XML Sitemaps with MULTIPLE SUB-SITEMAPS:
DOMAIN='https://www.xyz.com'
wget -q $DOMAIN/sitemap.xml --no-cache -O - | egrep -o "$DOMAIN[^<]+" | while read subsite;
do
echo --- Reading sub-sitemap: $subsite: ---
wget -q $subsite --no-cache -O - | egrep -o "$DOMAIN[^<]+" | while read line;
do
echo $line:
time curl -A 'Cache Warmer' -s -L $line > /dev/null 2>&1
@InpsydeNiklas
InpsydeNiklas / functions.php
Last active November 25, 2023 14:24
move PayPal button on product page below add to cart form
add_filter('woocommerce_paypal_payments_single_product_renderer_hook', function() {
return 'woocommerce_after_add_to_cart_form';
});
@shripadk
shripadk / README.md
Last active November 4, 2024 19:12
Karabiner Complex Modification: Change F4 to Command + Space for Alfred

Karabiner — Change F4 to Command + Space for Alfred

This is useful for changing the default F4 key that is bound to Spotlight to launch Alfred in macOS Big Sur.

Setup:

  1. Make sure you have Karabiner installed.
  2. Open ~/.config/karabiner/karabiner.json.
  3. Copy the rules object from below snippet and add it within profiles.complex_modifications. The basic structure of your karabiner.json file should look something like this: