How to Use it as a Part of Your Plugin or Theme

One of the useful features of my Simple Fields plugin is that you can easily make it a part of your custom WordPress plugin or a theme. But don’t forget that if you’re going to use this custom plugin or theme on multiple websites, developer license is required.

So, it can be done easily with three steps:

  1. Copy the content of assets and includes folders into your custom plugin,
  2. Include init.php file,
  3. Update the URLs in wp_register_style() and wp_register_script() functions (optional – it is only needed if you’re going to use some specific fields).

Now let’s take a step-by-step look into this process.

1. Copying “assets” and “includes” directories

Let’s assume that you’re developing a custom WordPress theme. Then after copying assets and includes directories, your theme structure may look like this:

simple fields file structure when using as a part of a theme

Feel free to rename these directories if you need to.

2. Including init.php file

Since we’re creating a theme, let’s open its functions.php file and add the following line there:

require_once( __DIR__ . '/includes/init.php' );

In case you renamed the includes directory, don’t forget about it here as well.

3. Registering plugin styles and scripts

The assets folder consists of 3 files:

For example let’s say that we’re not going to use fields in Gutenberg, in that case we need to only register main.js and main.css and we can do it by using the following code in our theme functions.php file:

add_action( 'admin_enqueue_scripts', function() {

	wp_register_style( 'sf_css', get_stylesheet_directory_uri() . '/assets/main.css' );
		get_stylesheet_directory_uri() . '/assets/main.js',
		array( 'jquery' )

} );

You can also find an example of this snippet in rudr-simple-fields.php file.

That’s pretty much it, now you can create fields!

Need more help?