WordPress theme core plugin. What is it for? Example open

WordPress theme core plugin. What is it for? Example

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators
Tested: Wordress 5+, PHP 7 +

It so happened that in WordPress the territory of the theme is understood only as files, functions and scripts that affect the appearance of your theme. All functionality, such as custom post types, widgets, secondary files are transferred to Сore plugin.

This is a plugin that is located in the directory of your theme and after activating which is available for installation in the admin-panel to expand the existing functionality of the theme.

The advantage of using the Core plugin is that after disabling or deleting the theme custom post types, widgets created by the theme will remain working.

Сore plugin example

Create a folder in the directory with the theme and name it – plugins. Inside which create another folder mycustomtheme-core.
In mycustomtheme-core create a file mycustomtheme-core.php and add the code below. It is also recommended to create an empty index.php file in the plugin folder for security.

<?php
/*
Plugin Name: MyCustomTheme Core
Plugin URI: https://mywebsite.com/plugin
Description: A plugin that expands the functionality of my theme
Version: 1.0
Author: AuthorName
Author URI: https://mywebsite.com
License: GPLv2 or later
Text Domain: your-textdomain-here
*/

if (!function_exists('add_action')) {
	echo '';
	exit; // check from what place the plug-in is started
}

//In the plugin directory, create an inc folder and transfer all the necessary files to it

require plugin_dir_path( __FILE__ ) . 'inc/widget.php';
require plugin_dir_path( __FILE__ ) . 'inc/custom-post-type.php'
require plugin_dir_path( __FILE__ ) . 'inc/acf.php'

?>

How to display a warning about the need to activate additional plugins after activating the theme is described in this article Connecting the necessary plugins for yours WordPress theme:

0

More

Leave a Reply

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

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation