Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Andy Feliciotti someguy9

🏠
Working from home
View GitHub Profile
View urlbox.php
//URLBOX
function urlbox_url_generate($url, $options){
$options['url'] = $url;
$options['url'] = preg_replace("(^https?://)", "", $options['url'] );
$format = isset($options['format']) ? $options['format'] : 'png';
unset($options['format']);
$_parts = [];
foreach ($options as $key => $values) {
$values = is_array($values) ? $values : [$values];
foreach ($values as $value) {
@someguy9
someguy9 / user-last-login-wordpress.php
Created Feb 21, 2021
Saves a WordPress user's last login and puts it in a sortable column in the WordPress dashboard
View user-last-login-wordpress.php
<?php
//Record user's last login to custom meta
add_action( 'wp_login', 'smartwp_capture_login_time', 10, 2 );
function smartwp_capture_login_time( $user_login, $user ) {
update_user_meta( $user->ID, 'last_login', time() );
}
//Register new custom column with last login time
add_filter( 'manage_users_columns', 'smartwp_user_last_login_column' );
View defer-js-wordpress.php
<?php
function smartwp_defer_js_parsing( $url ){
if(is_admin()) return $url; //Skip admin JS files
if(is_user_logged_in()) return $url; //Skip if user is logged in
if(false === strpos($url, '.js')) return $url; //If it's not a JS file skip
if(strpos($url, 'jquery.js')) return $url; //Don't defer jQuery
return str_replace(' src', ' defer src', $url); //defer JS file
}
add_filter( 'script_loader_tag', 'smartwp_defer_js_parsing', 10 );
@someguy9
someguy9 / example-usage-wp_enqueue_script.php
Created Feb 19, 2021
Example usage of wp_enqueue_script
View example-usage-wp_enqueue_script.php
<?php
function wp_smartwp_scripts_method() {
wp_enqueue_script( 'my-custom-script', get_stylesheet_directory_uri() . '/js/your_custom_script.js', array( 'jquery' ), true );
}
add_action( 'wp_enqueue_scripts', 'wp_smartwp_scripts_method' );
@someguy9
someguy9 / disable-core-update-emails-wordpress.php
Created Feb 17, 2021
Disable automatic "Your Site Has Been Updated..." emails
View disable-core-update-emails-wordpress.php
<?php
//Disable automatic "Your Site Has Been Updated..." emails
add_filter( 'auto_core_update_send_email', 'smartwp_disable_core_update_emails', 10, 4 );
function smartwp_disable_core_update_emails( $send, $type, $core_update, $result ) {
if ( !empty($type) && $type == 'success' ) {
return false;
}
return true;
}
@someguy9
someguy9 / allow-unsafe-link-target-wordpress.php
Created Feb 15, 2021
Removed rel="noopener" from links in WordPress
View allow-unsafe-link-target-wordpress.php
@someguy9
someguy9 / wordpress-get-featured-image-with-size.php
Created Dec 12, 2020
Displays the featured image in a <img> tag resized to the 'large' thumbnail size (use this in a loop)
View wordpress-get-featured-image-with-size.php
@someguy9
someguy9 / increase-wordpress-memory-limit.php
Created Oct 22, 2020
Increase WordPress memory limit (add this to wp-config.php)
View increase-wordpress-memory-limit.php
<?php
define('WP_MEMORY_LIMIT', '256M');
@someguy9
someguy9 / auto-wrap-youtube-videos.php
Created Oct 15, 2020
Auto wrap YouTube video embeds in WordPress with a div
View auto-wrap-youtube-videos.php
<?php
add_filter('embed_oembed_html', function ($html, $url, $attr, $post_id) {
if(strpos($html, 'youtube.com') !== false || strpos($html, 'youtu.be') !== false){
return '<div class="responsive-embed-container embed-responsive-16by9">' . $html . '</div>';
} else {
return $html;
}
}, 10, 4);