Skip to content

Instantly share code, notes, and snippets.

View someguy9's full-sized avatar
🏠
Working from home

Andy Feliciotti someguy9

🏠
Working from home
View GitHub Profile
@someguy9
someguy9 / disable-wordpress-admin-new-user-notification.php
Created May 14, 2020 19:05
Disable the WordPress new user email notification sent to the site admin
<?php
//Disable the new user notification sent to the site admin
function smartwp_disable_new_user_notifications() {
//Remove original use created emails
remove_action( 'register_new_user', 'wp_send_new_user_notifications' );
remove_action( 'edit_user_created_user', 'wp_send_new_user_notifications', 10, 2 );
//Add new function to take over email creation
add_action( 'register_new_user', 'smartwp_send_new_user_notifications' );
add_action( 'edit_user_created_user', 'smartwp_send_new_user_notifications', 10, 2 );
@someguy9
someguy9 / logged-in-wordpress-css.css
Created May 15, 2020 12:25
CSS to change the background color for logged in users
/* Change the background color for logged in users */
body.logged-in {
background-color: #BEBEBE
}
@someguy9
someguy9 / get-user-id-by-email.php
Created May 26, 2020 16:54
Gets the user ID by email in WordPress
<?php
//Get user ID by email
$user_data = get_user_by('email', '[email protected]');
$user_id = $user_data->ID;
$user_email = $user_data->user_email;
if(!empty($user_id)){
echo 'The user ID for '.$user_email.' is '.$user_id;
}
@someguy9
someguy9 / get-current-post-id.php
Last active May 26, 2020 17:19
Get the current post ID in WordPress
<?php
echo 'The current post ID is: '.get_the_ID();
@someguy9
someguy9 / get-post-id-by-slug.php
Last active May 26, 2020 17:23
Get WordPress post ID by slug
<?php
$post_data = get_page_by_path('my-post-slug');
$post_id = $post_data->ID;
if(!empty($post_id)){
echo 'The post ID is: '.$post_id;
}
@someguy9
someguy9 / disable-auto-update-emails.php
Created August 18, 2020 13:39
Disable the auto-update emails WordPress sends for plugins/themes (introduced in WP 5.5)
<?php
//Disable plugin auto-update email notification
add_filter('auto_plugin_update_send_email', '__return_false');
//Disable theme auto-update email notification
add_filter('auto_theme_update_send_email', '__return_false');
@someguy9
someguy9 / dark-mode-query.css
Created September 29, 2020 19:03
Media query for Dark Mode in CSS
/* Example dark mode color schema for CSS */
@media (prefers-color-scheme: dark) {
body {
background-color: #fff;
color: #000;
}
img {
opacity: .8;
transition: opacity .3s ease-in-out;
}
@someguy9
someguy9 / auto-wrap-youtube-videos.php
Created October 15, 2020 14:15
Auto wrap YouTube video embeds in WordPress with a div
<?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);
@someguy9
someguy9 / increase-wordpress-memory-limit.php
Created October 22, 2020 19:26
Increase WordPress memory limit (add this to wp-config.php)
<?php
define('WP_MEMORY_LIMIT', '256M');
memory_limit = 256M;