Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Andy Feliciotti someguy9

🏠
Working from home
View GitHub Profile
@someguy9
someguy9 / get-post-id-by-slug.php
Last active May 26, 2020
Get WordPress post ID by slug
View get-post-id-by-slug.php
<?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 / get-current-post-id.php
Last active May 26, 2020
Get the current post ID in WordPress
View get-current-post-id.php
<?php
echo 'The current post ID is: '.get_the_ID();
@someguy9
someguy9 / get-user-id-by-email.php
Created May 26, 2020
Gets the user ID by email in WordPress
View get-user-id-by-email.php
<?php
//Get user ID by email
$user_data = get_user_by('email', 'your@email.com');
$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 / wp-remove-gutenberg-block-library-css.php
Last active May 17, 2020
Removed the "/wp-includes/css/dist/block-library/style.min.css" file from your WordPress site
View wp-remove-gutenberg-block-library-css.php
<?php
//Remove Gutenberg Block Library CSS from loading on the frontend
function smartwp_remove_wp_block_library_css(){
wp_dequeue_style( 'wp-block-library' );
wp_dequeue_style( 'wp-block-library-theme' );
wp_dequeue_style( 'wc-block-style' ); // Remove WooCommerce block CSS
}
add_action( 'wp_enqueue_scripts', 'smartwp_remove_wp_block_library_css', 100 );
@someguy9
someguy9 / logged-in-wordpress-css.css
Created May 15, 2020
CSS to change the background color for logged in users
View logged-in-wordpress-css.css
/* Change the background color for logged in users */
body.logged-in {
background-color: #BEBEBE
}
@someguy9
someguy9 / disable-wordpress-admin-new-user-notification.php
Created May 14, 2020
Disable the WordPress new user email notification sent to the site admin
View disable-wordpress-admin-new-user-notification.php
<?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 );
View wp-check-user-capability.php
<?php
if( current_user_can('manage_options') ) {
echo 'This user can manage WordPress options. (Settings Page)';
};
@someguy9
someguy9 / replace-dashboard-icon-wp-admin.php
Last active Apr 2, 2020
Adds a custom logo to the top left of the WordPress admin
View replace-dashboard-icon-wp-admin.php
<?php
//Adds a custom logo to the top left of the WordPress admin
function smartwp_custom_logo_wp_dashboard() {
echo "<style type='text/css'>
#wpadminbar #wp-admin-bar-wp-logo > .ab-item .ab-icon:before {
background-image: url('" . get_bloginfo('stylesheet_directory') . "/admin-icon.png');
background-size: contain;
background-position: 0 0;
color:rgba(0, 0, 0, 0);
}
@someguy9
someguy9 / remove-jquery-migrate.php
Created Mar 17, 2020
Remove jQuery migrate from WordPress
View remove-jquery-migrate.php
<?php
//Remove jQuery migrate
function smartwp_remove_jquery_migrate( $scripts ) {
if ( !is_admin() && !empty( $scripts->registered['jquery'] ) ) {
$scripts->registered['jquery']->deps = array_diff( $scripts->registered['jquery']->deps, ['jquery-migrate'] );
}
}
add_action('wp_default_scripts', 'smartwp_remove_jquery_migrate');
@someguy9
someguy9 / disable-xml-rpc.php
Created Mar 17, 2020
Disable XML-RPC in WordPress
View disable-xml-rpc.php
<?php
//Disable XML-RPC
add_filter('xmlrpc_enabled', '__return_false');
You can’t perform that action at this time.