Creating a functionality plugin is an alternative way of creating a child theme to add functionality to a website for those who use themeless builders like Breakdance or themes that cannot have child themes like Spectra one.
Create the Folder and File for the Plugin
The first step is to create the folder and file in the wp-content/plugins folder, in the example below we create the ak-functions folder, then create the functions.php file inside that folder
cd wp-content/plugins
mkdir ak-functions
cd ak-functions
nano functions.php
If you can’t access SSH, you can create the folder and file using the file manager from your web panel.
Write the Code in the functions.php File
Then fill in the code for the functions you want to add to your WordPress, a header comment must contain the Plugin Name:
/**
* Plugin Name: YOUR PLUGIN NAME
**/
An example:
<?php
/**
* Plugin Name: Akah Functionality Plugin
**/
add_action( 'template_redirect', function(){
global $wp;
if ( $wp->request == 'test/my-custom-plugin' ) {
echo 'Hello World!';
die;
}
} );
Activate the Plugin and Test it
After that, activate the plugin that you just created, then test it by visiting into https://yourwebsite.com/test/my-custom-plugin
If the Hello World text appears successfully! You can delete lines 6 to 12, then start inserting additional functions that you usually put in the functions.php file in the child theme.
Happy coding!