Adding additional functionality to a WordPress website via Functionality plugin

Traditionally, adding new functions to extend the functionality of a WordPress site is achieved by adding the code snippets to the active theme’s functions.php file. That approach proves working but there are a few drawbacks. First of all, if the theme that is used is changed the added functionality will get lost as the functions.php file is located in the active theme’s folder. Secondly, theme updates can override the functions.php file which will lead to the same result.

That problem can be solved by creating a plugin which will hold all of the additionally added functions. Since all active plugins are loaded on every page (as well as functions.php) it won’t make a difference whether the additional functions appear in the functions.php file or in the plugin.

Here is how to do it:

1. Create a new folder in wp-contents/plugins (mine was called functionality-plugin)
2.Inside the folder create a new file with .php extention. (mine was called jsn-functionality-plugin.php)
3.Open the file to edit it.
4.At the top of the file write plugin information, so WordPress can properly recognize it. (example below)


<?php
/*
Plugin Name:JSN Functionality Plugin 
Plugin URI: https://jsndesign.co.uk
Description: Plugin to add additional functionality. Moves functions from functions.php making the WordPress installation not dependent on a specific theme.
Author: Yasen Lilov
Version: 1.0
Author URI: https://jsndesign.co.uk
License: GPL2
*/

Once that is done you are you can place all of the additional functions in the file.
Here are some examples of how to:
1.Change the login logo’s url.
2.Have the “remember me” button always checked at login.
3.Change the login error message to remove the default hints.


<?php
/*
Plugin Name:JSN Functionality Plugin 
Plugin URI: https://jsndesign.co.uk
Description: Plugin to add additional functionality. Moves functions from functions.php making the WordPress installation not dependent on a specific theme.
Author: Yasen Lilov
Version: 1.0
Author URI: https://jsndesign.co.uk
License: GPL2
*/

// Change the logo url to the website url (isntead of wordpress.org)
function my_login_logo_url() {
return get_bloginfo( 'url' );
}
add_filter( 'login_headerurl', 'my_login_logo_url' );

// Have the login check button always checked

function login_checked_remember_me() {
add_filter( 'login_footer', 'rememberme_checked' );
}
add_action( 'init', 'login_checked_remember_me' );

function rememberme_checked() {
echo "<script>document.getElementById('rememberme').checked = true;</script>";
}

// Change of the login error message - to prevent hint of which part - password or account was wrong
function login_error_override()
{
    return 'Incorrect login details.';
}
add_filter('login_errors', 'login_error_override');


The last thing to do is to go to the WordPress site’s Dashboard > Plugins and activate the plugin that was created.

Useful Sources:

WordPress Functions Reference
WordPress – Writing a Plugin

Share this Post

Leave a Reply

Your email address will not be published. Required fields are marked *