
WordPress plugins are add-ons that can be installed on a WordPress website to extend its functionality and capabilities. They can be used to add new features, modify existing ones, or integrate with other software and services.
To create a basic WordPress plugin, follow these steps:
<?php
/*
Plugin Name: My Plugin
Description: This is my first WordPress plugin.
Version: 1.0
Author: Your Name
*/
PHPfunction my_plugin_activate() {
// Perform setup tasks here
}
register_activation_hook( __FILE__, 'my_plugin_activate' );
PHPfunction my_plugin_deactivate() {
// Perform cleanup tasks here
}
register_deactivation_hook( __FILE__, 'my_plugin_deactivate' );
PHPfunction my_plugin_shortcode( $atts ) {
// Extract shortcode attributes
extract( shortcode_atts(
array(
'id' => '',
),
$atts
) );
// Return YouTube embed code
return '<iframe width="400" height="300" src="https://www.youtube.com/embed/hbJiwm5YL5Q" title="WordPress Plugin Development: Gutenberg Blocks, React & More" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';
}
add_shortcode( 'youtube', 'my_plugin_shortcode' );
PHPwp-content/plugins
directory on your WordPress site.12345
, you would use the following shortcode in a post or page: [youtube id="12345"]
.Note: You can find more detailed information about creating WordPress plugins and using WordPress hooks and filters in the WordPress Codex (https://codex.wordpress.org/Plugin_API).