WordPress Functions.php

Some WordPress functions.php snippets can make a huge difference or have a small impact that make a better website.

By ♟ Maggew.comUpdated   675 Views
blue elephant plush toy on black laptop computer

Here are some of my favorite functions.php snippets to include when starting a new website. If you want, you can use a plugin called Code Snippets and add / import / export functions that way.

If using GeneratePress theme, the functions.php might not be as popular because GP gives you customization options that you would otherwise need a functions.php snippet for… just sayin'.

Display Last Updated Date

I recommend using the WP Last Modified Info plugin.

// Add "[modified_date]" to the display

function post_modified_date() {
    return get_the_modified_date();
}
add_shortcode( 'modified_date', 'post_modified_date' );

Allows JSON, SVG, etc in the Media Library

// Copy and paste this block of code to the functions.php file of your child theme

function divi_engine_custom_mime_types($mimes) {

    // Add your additional allowed mime types here from the list above.
    $mimes['txt'] = 'text/plain';
    $mimes['json'] = 'application/json';
    $mimes['svg'] = 'image/svg+xml';
    $mimes['mov'] = 'video/quicktime'; // Add .mov MIME type

    // Optionally, you can also remove MIME-types.
    unset($mimes['exe']);

    return $mimes;
}
add_filter('upload_mimes', 'divi_engine_custom_mime_types');

Disable WordPress Administration email verification prompt

add_filter( 'admin_email_check_interval', '__return_false' );

Misc Links

  • https://themeisle.com/blog/wordpress-functions-php-guide/
  • https://www.wpkube.com/code-snippets-wordpress/
  • https://docs.generatepress.com/article/show-the-updated-post-date/
  • https://www.wpglossy.com/show-last-updated-date-in-generatepress-theme/

Here are some of my favorite functions.php snippets to include when starting a new website. If you want, you can use a plugin called Code Snippets and add / import / export functions that way.

If using GeneratePress theme, the functions.php might not be as popular because GP gives you customization options that you would otherwise need a functions.php snippet for… just sayin'.

Display Last Updated Date

I recommend using the WP Last Modified Info plugin.

// Add "[modified_date]" to the display

function post_modified_date() {
    return get_the_modified_date();
}
add_shortcode( 'modified_date', 'post_modified_date' );

Allows JSON, SVG, etc in the Media Library

// Copy and paste this block of code to the functions.php file of your child theme

function divi_engine_custom_mime_types($mimes) {

    // Add your additional allowed mime types here from the list above.
    $mimes['txt'] = 'text/plain';
    $mimes['json'] = 'application/json';
    $mimes['svg'] = 'image/svg+xml';
    $mimes['mov'] = 'video/quicktime'; // Add .mov MIME type

    // Optionally, you can also remove MIME-types.
    unset($mimes['exe']);

    return $mimes;
}
add_filter('upload_mimes', 'divi_engine_custom_mime_types');

Disable WordPress Administration email verification prompt

add_filter( 'admin_email_check_interval', '__return_false' );

Misc Links

  • https://themeisle.com/blog/wordpress-functions-php-guide/
  • https://www.wpkube.com/code-snippets-wordpress/
  • https://docs.generatepress.com/article/show-the-updated-post-date/
  • https://www.wpglossy.com/show-last-updated-date-in-generatepress-theme/
Item added to cart.
0 items - $0