Dalton Sutton
Dalton SuttonLiberty-minded. Musician.
Full Stack Developer.
Code Snippets tagged with #wordpress
Here are some helpful code snippets that you might find useful.
<?php

// Function to remove various default dashboard widgets to declutter the user interface
function daltonsutton_remove_dashboard_widgets() {
  remove_meta_box('dashboard_right_now', 'dashboard', 'normal');
  remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
  remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal');
  remove_meta_box('dashboard_plugins', 'dashboard', 'normal');
  remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
  remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side');
  remove_meta_box('dashboard_primary', 'dashboard', 'side');
  remove_meta_box('dashboard_secondary', 'dashboard', 'side');
  remove_meta_box('dashboard_activity', 'dashboard', 'normal');
  remove_meta_box('dashboard_site_health', 'dashboard', 'normal');
  remove_action('welcome_panel', 'wp_welcome_panel');
}
add_action('admin_init', 'daltonsutton_remove_dashboard_widgets');
WordPess Remove Dashboard Widgets
#wordpress#admin#admin_init
PHP
<?php 

function daltonsutton_svg_mime_types($mimes) {
  $mimes['svg'] = 'image/svg+xml';
  return $mimes;
}
add_filter('upload_mimes', 'daltonsutton_svg_mime_types');
WordPress Allow SVG Uploads
#wordpress#upload_mimes
PHP
<?php 

// rename route /author/ to /members/
function daltonsutton_rename_author_to_members() {
    global $wp_rewrite;
    $wp_rewrite->author_base = 'members';
    $wp_rewrite->author_structure = '/' . $wp_rewrite->author_base. '/%author%';
}
add_action('init', 'daltonsutton_rename_author_to_members');

// rewrite route /author/ to /members/
function daltonsutton_rewrite_author_to_members() {
    add_rewrite_rule('^members/([^/]+)/?', 'index.php?author_name=$matches[1]', 'top');
}
add_action('init', 'daltonsutton_rewrite_author_to_members');
WordPress Custom Author Permalink
#wordpress#author#init#permalink
PHP
<?php 

// WordPress Login Page CSS Customization
function daltonsutton_login_css() {
    echo '
        <style type="text/css">
            *:focus {
                outline: none !important;
            }

         
WordPress Custom Login Styles
#wordpress#wp_head
PHP
<?php 

// add a meta description to the head
function daltonsutton_meta_description() {
    if (is_home()):
        echo '<meta name="description" content="'.get_bloginfo('description').'" />'.PHP_EOL;
    endif;
    if (is_single() || is_page()):
        if ($excerpt = get_the_excerpt()):
            echo '<meta name="description" content="' . $excerpt . '" />'.PHP_EOL;
     
WordPress Custom Meta Description
#wordpress#wp_head
PHP
<?php 

function daltonsutton_smtp_settings( $phpmailer ) {
    $phpmailer->isSMTP();

    $phpmailer->Host       = 'smtp.mailgun.org';
    $phpmailer->Username   = '[email protected]';
    $phpmailer->Password   = 'password123';
    $phpmailer->SMTPSecure = 'ssl';
    $phpmailer->SMTPAuth   = true;
    $phpmailer->Port       = 465;
    $phpmailer->From       =
WordPress Custom SMTP
#wordpress#phpmailer_init
PHP
<?php 

// Not everyone is a cowboy.
function daltonsutton_replace_howdy($wp_admin_bar) {
    $my_account = $wp_admin_bar->get_node('my-account');
    $newtitle = str_replace( 'Howdy, ', 'Logged in as ', $my_account->title );            
    $wp_admin_bar->add_node( array(
        'id' => 'my-account',
        'title' => $newtitle,
    ) );
}
add_filter('admin_bar_menu', 'daltonsutton_replace_howdy', 25);
WordPress Replace "Howdy"
#wordpress#admin_bar_menu
PHP
<?php 

// Rewrite Welcome to WordPress text in bottom right hand corner.
function daltonsutton_replace_footer_admin() {
    echo '<span id="footer-thankyou">&copy; '.date('Y').' <a href="'.get_bloginfo( 'url' ).'">'.get_bloginfo( 'name' ).'</a>. All rights reserved.</span>';
}
add_filter('admin_footer_text', 'daltonsutton_replace_footer_admin');

// Rewrite WordPress version in bottom right hand corner.
function daltonsutton_replace_footer_version() {
    echo 'WordPress v'.$GLOBALS['wp_version'];
}
add_filter('update_footer', 'daltonsutton_replace_footer_version', 9999);
WordPress Replace Admin Footer
#wordpress#admin#admin_footer_text#update_footer
PHP
© 2024 Dalton Sutton. All rights reserved.