Skip to content

Instantly share code, notes, and snippets.

@alexander-young
alexander-young / functions.php
Created January 17, 2022 17:00
WP Basic Cleanup
<?php
// //remove emoji support
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
// // Remove rss feed links
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );
<?php
add_post_meta( 5, 'fruit', 'orange', false );
add_post_meta( 5, 'fruit', 'grape', false );
add_post_meta( 5, 'fruit', 'apple', false );
add_post_meta( 5, 'veggie', 'carrot', false );
print_r(get_post_meta( 5, 'fruit', false ));
@alexander-young
alexander-young / index.php
Created December 1, 2020 21:41
WordPress Custom Queries Example
// Get Posts
$posts = get_posts([
'post_type' => 'press-release',
'posts_per_page' => 25,
'category' => 4,
]);
foreach($posts as $post){
setup_postdata($post);
@alexander-young
alexander-young / functions.php
Created January 15, 2020 20:07
Allow SVGs in WordPress media library
function upload_svg_files( $allowed ) {
if ( !current_user_can( 'manage_options' ) )
return $allowed;
$allowed['svg'] = 'image/svg+xml';
return $allowed;
}
add_filter( 'upload_mimes', 'upload_svg_files');
@alexander-young
alexander-young / functions.php
Created January 15, 2020 05:27
Cleanup WordPress plugin admin
// Removing plugin controls from admin
function remove_plugin_controls($actions, $plugin_file, $plugin_data, $context){
if (array_key_exists('edit', $actions)) {
unset($actions['edit']);
}
if (array_key_exists('deactivate', $actions)) {
@alexander-young
alexander-young / functions.php
Created January 15, 2020 02:32
Defer Javascript in WordPress
function defer_parsing_of_js($url)
{
if (is_admin()) return $url; //don't break WP Admin
if (false === strpos($url, '.js')) return $url;
if (strpos($url, 'jquery.js')) return $url;
return str_replace(' src', ' defer src', $url);
}
add_filter('script_loader_tag', 'defer_parsing_of_js', 10);
@alexander-young
alexander-young / steps.md
Created November 6, 2019 03:42
Install Redis for WordPress

Installing Redis

  • sudo apt update
  • sudo apt install redis-server
  • sudo nano /etc/redis/redis.conf
  • supervised systemd
  • maxmemory 128M
  • maxmemory-policy allkeys-lfu
  • sudo systemctl restart redis.service
  • sudo systemctl status redis
  • redis-cli and ping
@alexander-young
alexander-young / .htaccess
Created August 17, 2018 16:44
WordPress - Increase maximum upload size
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300
rsync -rlmvz --size-only --ipv4 --progress -e 'ssh -p 2222' <env>.<site_id>@appserver.<env>.<site_id>.drush.in:files/ .
<?xml version="1.0"?>
<ruleset name="WordPress Theme Coding Standards">
<!-- See https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
<!-- See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/WordPress-Core/ruleset.xml -->
<!-- Set a description for this ruleset. -->
<description>A custom set of code standard rules to check for WordPress themes.</description>
<!-- Include the WordPress ruleset, with exclusions. -->
<rule ref="WordPress">