Skip to content

Instantly share code, notes, and snippets.

@jbd91
jbd91 / snippet.php
Created June 8, 2020 19:53
Find Enqueued WP Script Handles
function wpa54064_inspect_scripts() {
global $wp_scripts;
foreach( $wp_scripts->queue as $handle ) :
echo $handle;
endforeach;
}
add_action( 'wp_print_scripts', 'wpa54064_inspect_scripts' );
@jbd91
jbd91 / snippet.php
Last active June 8, 2020 19:52
async
function add_async_forscript($url)
{
if (strpos($url, '#asyncload')===false)
return $url;
else if (is_admin())
return str_replace('#asyncload', '', $url);
else
return str_replace('#asyncload', '', $url)."' async='async";
}
add_filter('clean_url', 'add_async_forscript', 11, 1);
@jbd91
jbd91 / snippet.txt
Last active January 23, 2020 19:51
Wordpress Links
https://kinsta.com/blog/defer-parsing-of-javascript/
https://mobile1st.com/7-ways-to-improve-mobile-page-speed/
@jbd91
jbd91 / craft.txt
Last active January 8, 2020 21:56
Installing Craft 3 locally with MAMP
https://docs.craftcms.com/v3/installation.html#step-1-download-craft
Make sure hidden files are visible
Download Craft zip file from link above or install with composer: composer create-project craftcms/craft <Path>
Open MAMP -- no need to start servers yet -- go to Preferences > Web Server and set the document root to be the "web" folder inside the Craft directory.
Set Permissions on directories within project:
@jbd91
jbd91 / snippet.php
Created November 5, 2019 20:28
Black List IPs
<?php
//wp-config
$blocked_IPs = array(
'93.160.60.22',
'188.213.49.139'
);
if (in_array($_SERVER['REMOTE_ADDR'], $blocked_IPs)) {
header('HTTP/1.0 301 Moved Permanently');
header('Location: https://www.youtube.com/watch?v=dQw4w9WgXcQ');
@jbd91
jbd91 / snippet.php
Created November 5, 2019 17:00
Register Widget Area
// Register
<?php
function language_select_widget_init() {
register_sidebar( array(
'name' => 'Language Select',
'id' => 'fdi_language_select',
) );
}
@jbd91
jbd91 / snippet.php
Created October 28, 2019 14:24
WP Query -- Query by Page Template
<?php
$args = [
'post_type' => 'page',
'meta_query' => [
[
'key' => '_wp_page_template',
'value' => 'page-industry-detail.php'
]
]
];
@jbd91
jbd91 / snippet.php
Last active October 16, 2019 14:24
WP Query
<?php
$args = [
'post_type' => 'page',
'posts_per_page' => -1,
];
$query = new WP_Query($args);
if ($query->have_posts()) : ?>
@jbd91
jbd91 / snippet.txt
Created September 26, 2019 21:31
Fix for AWS permissions NS
open console screen:
sudo ./fixperms.sh
@jbd91
jbd91 / snippet.js
Created September 17, 2019 19:00
Print Year to page
// client side solution rather than server (PHP) useful for theme options to create a dynamic copyright date
<script type="text/javascript">document.write(new Date().getFullYear())</script>