Created
February 11, 2020 21:10
-
-
Save StoyPenny/2fd16523f76c2daa2fb7f34eb9e7c3e9 to your computer and use it in GitHub Desktop.
Basic WordPress Plugin Template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Test plugin | |
Description: A test plugin to demonstrate wordpress functionality | |
Author: Chris Steurer | |
Version: 0.0.1 | |
*/ | |
/** | |
* Create Admin Menu & Page | |
*/ | |
add_action('admin_menu', 'test_plugin_setup_menu'); | |
function test_plugin_setup_menu(){ | |
add_menu_page( 'Test Plugin Page', 'Test Plugin', 'manage_options', 'test-plugin', 'test_init' ); | |
} | |
/** | |
* Show Content on the admin Screen | |
*/ | |
function test_init(){ | |
echo "<h1>Hello World!</h1>"; | |
} | |
/** | |
* Load Styles and Scripts | |
* | |
* @desc Load custom CSS and JS files on specific pages of your plugin based on the page slug. | |
*/ | |
add_action('admin_enqueue_scripts', 'load_css_and_js'); | |
function load_css_and_js($hook) { | |
$current_screen = get_current_screen(); | |
if ( strpos($current_screen->base, 'my-fist-slug') === false) { | |
return; | |
} else { | |
wp_enqueue_style('boot_css', plugins_url('inc/bootstrap.css',__FILE__ )); | |
wp_enqueue_script('boot_js', plugins_url('inc/bootstrap.js',__FILE__ )); | |
wp_enqueue_script('ln_script', plugins_url('inc/main_script.js', __FILE__), ['jquery'], false, true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment