Plugin — Create a plugin - martindubenet/Wordpress GitHub Wiki

What, Why, and How-To’s of Creating a Site-Specific WordPress Plugin


  1. Go to the plugins repository: …/wp-content/plugins/,
  2. Create a folder : my-plugin/,
  3. Open that new directory and create a new PHP file with that same name : my-plugin/my-plugin.php,
  4. Wordpress requires to have these two comment lines at the beginning of the PHP file to recognise your plugin as one.
<?php
/*
Plugin Name: Site Plugin for example.com
Description: Site specific code changes for example.com
*/

Now that this is done you simply add here whatever function example(){...} you want.

<?php
/*
Plugin Name: Wine Post Type
Description: Add a custom post type for wine bottles for sales.
*/

/* Register Custom Post Type for Wine Bottle */
function plugin_wine_post_type() {

    register_post_type( 'wine',
        // WordPress CPT Options Start
        array(
            'labels' => array(
                'name' => __( 'Wines' ),
                'singular_name' => __( 'Wine' ),
		'add_new_item'       => __( 'Add a new wine', 'thisTheme' ),
		'new_item'           => __( 'New wine', 'thisTheme' ),
		'edit_item'          => __( 'Edit wine', 'thisTheme' ),
		'view_item'          => __( 'View the wine', 'thisTheme' ),
		'all_items'          => __( 'All wines', 'thisTheme' ),
		'search_items'       => __( 'Search a wine', 'thisTheme' ),
		'parent_item_colon'  => __( 'Wine type:', 'thisTheme' ),
		'not_found'          => __( 'No wine found.', 'thisTheme' ),
		'not_found_in_trash' => __( 'No wine found in Trash.', 'thisTheme' )
            ),
            'has_archive' => true,
            'public' => true,
            'rewrite' => array('slug' => 'wine'),
            'show_in_rest' => true,
            'supports' => array('editor')
        )
    );
}
 
add_action( 'init', 'plugin_wine_post_type' );