Image
Wordpress typewriter

WordPress has many theming functions available to ease front end development. Some are bundled as plugins, while others are added to the theme’s functions.php file. There are pros and cons to each approach. A plugin should really be added for each individual function, which results in a large number of custom plugins to maintain. The best functions just require a few simple lines of code, making them easier to manage in one file (functions.php), and in one location.

Here are 5 incredibly useful functions that are simple to implement:

  1. Enqueue scripts

    Most projects require additional Javascript or CSS files, including Bootstrap (if not using a starter theme) or Font Awesome. This function allows you to add scripts to your theme with customizable options, such as adding script to the footer, as well as any dependencies, including jQuery.

  2. Register Nav

    This handy function allows you to add multiple menu locations to your theme. Rarely does a website rely on one singular menu. Often there’s one menu for utility links, social media, the footer, etc. Once the new menu locations are registered in the functions.php file, they will be available in the WordPress UI. In the template, this code can be called a few ways, the primary being this PHP array:

    wp_nav_menu( array( 'sort_column' =---->'menu_order', 'theme_location' => 'header_menu', 'menu_class' => 'css-menu', 'title_li' => '', 'link_before' => '', 'link_after' => '' ) );

    Or, if utilizing a Sage theme:

    {!! wp_nav_menu(['theme_location' => 'footer_navigation', 'menu_class' => 'nav-footer']) !!}
  3. Remove Post Support

    This is a very simple function with one goal: to unregister a feature from a post type. The two parameters are post_type and support_feature. The feature options include title, excerpt, thumbnail, the editor and several more. I find this most helpful when disabling comments on a particular post type.

  4. Add Image Size

    WordPress comes with 4 default sizes, however most websites need more than the default options. This function allows flexibility in having users upload one image and then programmatically displaying that image in any shape or size necessary. The function takes 3 parameters: width, height, and crop. An image regeneration plugin will be necessary if adding the image sizes after the images have been uploaded through the WordPres UI.

  5. Tiny MCE

    A standard WYSIWYG has common styles, however more often than not, a website requires content users to have access to additional features. This function accepts sets of arrays, one array for each format, with 4 keys: title, block, classes, and wrapper. After implementing this function, users are able to highlight text and apply custom styles within the WordPress UI.

Hopefully you find this short list of functions helpful in your development process. While a plugin may be easier to install, adding these functions to your functions.php file allows for complete control over the desired result. WordPress does a great job of detailing available functions with parameter information and explanations of use.