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-admin-bar-wordpress.php
Created March 16, 2020 21:39
Disable WordPress admin bar
<?php
//Disable WordPress admin bar for all logged in users
add_filter('show_admin_bar', '__return_false');
<?php
// Changing excerpt more
function smartwp_change_excerpt_more_text( $more ){
global $post;
return '&hellip; <a class="read-more" href="'.get_permalink($post->ID).'" title="'.esc_attr(get_the_title($post->ID)).'">'.'Read More &raquo;'.'</a>';
}
add_filter('excerpt_more', 'smartwp_change_excerpt_more_text');
@someguy9
someguy9 / change-excerpt-length-wordpress.php
Created March 17, 2020 12:27
Change the default excerpt length in WordPress (default is 55 words)
<?php
//Change the default excerpt length in WordPress (default is 55 words)
function smartwp_change_excerpt_length( $length ) {
return 24;
}
add_filter( 'excerpt_length', 'smartwp_change_excerpt_length', 9999);
@someguy9
someguy9 / add-admin-user-wordpress.php
Created March 17, 2020 12:35
Create an admin user in WordPress
<?php
//Create an admin user
function smartwp_create_admin_user(){
$username = 'yourusername';
$password = '2JyAEQJ9B9Jf5T8a';
$email = 'change@me.com';
//This will ensure it only tries to create the user once (based on email/username)
if ( !username_exists( $username ) && !email_exists( $email ) ) {
$userid = wp_create_user( $username, $password, $email );
$user = new WP_User( $userid );
@someguy9
someguy9 / enable-shortcodes-in-text-widgets.php
Created March 17, 2020 12:38
Enable shortcodes in text widgets (WordPress)
<?php
//Enable shortcodes in text widgets
add_filter('widget_text', 'do_shortcode');
@someguy9
someguy9 / enable-svg-upload.php
Created March 17, 2020 12:44
Enable SVG upload in WordPress
<?php
//Enable SVG upload
function smartwp_enable_svg_upload( $mimes ) {
//Only allow SVG upload by admins
if ( !current_user_can( 'administrator' ) ) {
return $mimes;
}
$mimes['svg'] = 'image/svg+xml';
$mimes['svgz'] = 'image/svg+xml';
@someguy9
someguy9 / disable-xml-rpc.php
Created March 17, 2020 12:46
Disable XML-RPC in WordPress
<?php
//Disable XML-RPC
add_filter('xmlrpc_enabled', '__return_false');
@someguy9
someguy9 / remove-jquery-migrate.php
Created March 17, 2020 12:51
Remove jQuery migrate from WordPress
<?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 / replace-dashboard-icon-wp-admin.php
Last active April 2, 2020 23:42
Adds a custom logo to the top left of the WordPress admin
<?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);
}
<?php
if( current_user_can('manage_options') ) {
echo 'This user can manage WordPress options. (Settings Page)';
};