Skip to content

Instantly share code, notes, and snippets.

View IlanVivanco's full-sized avatar
💡
Coding!

Ilán Vivanco IlanVivanco

💡
Coding!
View GitHub Profile
@IlanVivanco
IlanVivanco / wordpress-menu-filter.php
Last active March 16, 2021 12:55
Add a shortcode to a specific menu item
<?php
/**
* Filters all menu item URLs for a #placeholder#.
*
* @param WP_Post[] $menu_items All of the nave menu items, sorted for display.
*
* @return WP_Post[] The menu items with any placeholders properly filled in.
*/
function iv_dynamic_menu_items( $menu_items ) {
@IlanVivanco
IlanVivanco / .htaccess
Last active March 16, 2021 12:49
Browser cache
# Enable Compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
@IlanVivanco
IlanVivanco / replace_relative_urls.sql
Last active March 16, 2021 12:56
Replace WP relative URLs images
UPDATE
wp_posts
SET
post_content = (
REPLACE(post_content, 'src="http://', 'src="//')
)
WHERE
INSTR(post_content, 'jpeg') > 0
OR INSTR(post_content, 'jpg') > 0
OR INSTR(post_content, 'gif') > 0
@IlanVivanco
IlanVivanco / count-number-of-pages.sql
Last active March 16, 2021 12:56
Find pages using a template
SELECT
COUNT(*) as total
FROM
wp_posts as p
JOIN wp_postmeta as m ON p.ID = m.post_id
WHERE
p.`post_type` = 'page'
AND p.`post_status` = 'publish'
AND m.`meta_key` = '_wp_page_template'
AND m.`meta_value` = 'page-your-template-name.php'
@IlanVivanco
IlanVivanco / paralelize_downloads.php
Last active March 16, 2021 13:26
Paralelize downloads in order to increase speed over HTTP 1.1
<?php
/**
* Paralelize download test
*/
add_filter( 'wp_get_attachment_url', 'iv_parallelize_hostnames', 10, 2 );
function iv_parallelize_hostnames( $url, $id ) {
$hostname = iv_get_hostname( $url );
@IlanVivanco
IlanVivanco / download_files.txt
Last active March 16, 2021 12:43
Download multiple files using wget
https://example.com/file1.gz
https://example.com/file2.gz
https://example.com/file3.gz
@IlanVivanco
IlanVivanco / db_clean_up.sql
Last active February 9, 2022 11:18
Wordpress DB clean up
-- Deletes old revisions
DELETE a,
b,
c
FROM
wp_posts a
LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)
LEFT JOIN wp_term_taxonomy d ON (b.term_taxonomy_id = d.term_taxonomy_id)
WHERE
@IlanVivanco
IlanVivanco / autoloaded_data.sql
Last active March 16, 2021 13:26
Show WP autoloaded data
SELECT
'autoloaded data' as name,
ROUND(SUM(LENGTH(option_value))) as value
FROM
wp_options
WHERE
autoload = 'yes'
UNION
SELECT
'autoloaded data count',
@IlanVivanco
IlanVivanco / update_post_count_on_tax.sql
Last active March 16, 2021 13:26
Update Post Count on Taxonomies
UPDATE
wp_term_taxonomy
SET
count = (
SELECT
COUNT(*)
FROM
wp_term_relationships rel
LEFT JOIN wp_posts po ON (po.ID = rel.object_id)
WHERE