Some of my personal favourite functions

aarmstrongplott

Ashley Armstrong

Posted on June 10, 2021

Some of my personal favourite functions

Using Gravity Forms?

You can only return a US or International Phone Number; using this function we can return a UK Phone Format:


// Add UK phone number to Gravity Phone number using REGEX

add_filter( 'gform_phone_formats', 'uk_phone_format' );
function uk_phone_format( $phone_formats ) {
    $phone_formats['uk'] = array(
        'label'       => 'UK',
        'mask'        => false,
        'regex'       => '/^(((\+44\s?\d{4}|\(?0\d{4}\)?)\s?\d{3}\s?\d{3})|((\+44\s?\d{3}|\(?0\d{3}\)?)\s?\d{3}\s?\d{4})|((\+44\s?\d{2}|\(?0\d{2}\)?)\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$/',
        'instruction' => false,
    );

    return $phone_formats;
}
Enter fullscreen mode Exit fullscreen mode

Switch from Gutenberg to Classic Editor

This will switch you back to the classic editor and remove the Gutenberg styling

add_filter("use_block_editor_for_post_type", "disable_gutenberg_editor");
function disable_gutenberg_editor(){
    return false;
}

//Remove Gutenberg Block Library CSS from loading on the frontend
function 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', 'remove_wp_block_library_css', 100 );
Enter fullscreen mode Exit fullscreen mode

Reduce the risk of being hacked!

Disabling XMLPRC can help reduce the amount of hackers trying to gain access to your site

add_filter('xmlrpc_enabled', '__return_false');
Enter fullscreen mode Exit fullscreen mode

Change the max image size before it's scaled.

add_filter( 'max_srcset_image_width', 'plott_max_srcset_image_width', 10 , 2 );

// set the max image width
function plott_max_srcset_image_width() {
    return 2200;
}
Enter fullscreen mode Exit fullscreen mode

Change the url for the logo in WordPress admin login

function theme_url( $url ) {
   return get_bloginfo( 'url' );
}

add_filter( 'login_headerurl', 'theme_url' );
Enter fullscreen mode Exit fullscreen mode

Change the category checkboxes to radio buttons

<?php
function admin_js() { ?>
    <script type="text/javascript">

        jQuery(document).ready( function () {
            jQuery('form#post').find('.categorychecklist input').each(function() {
                var new_input = jQuery('<input type="radio" />'),
                    attrLen = this.attributes.length;

                for (i = 0; i < attrLen; i++) {
                    if (this.attributes[i].name != 'type') {
                        new_input.attr(this.attributes[i].name.toLowerCase(), this.attributes[i].value);
                    }
                }

                jQuery(this).replaceWith(new_input);
            });
        });

    </script>
<?php }
add_action('admin_head', 'admin_js');
Enter fullscreen mode Exit fullscreen mode

There you go; some of best and favourite functions that I use to make my life easier when developing sites for clients that are always in my base theme.

💖 💪 🙅 🚩
aarmstrongplott
Ashley Armstrong

Posted on June 10, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related