Plugin Development Code Example

Creating a Basic WordPress Plugin:

/* Plugin Name: My Custom Plugin */ // Plugin functionality goes here

Adding a Shortcode in a Plugin:

function custom_shortcode_function() { return 'Hello, this is a custom shortcode!'; } add_shortcode('custom_shortcode', 'custom_shortcode_function');

Creating a Custom Widget:

class Custom_Widget extends WP_Widget { // Widget implementation here } register_widget('Custom_Widget');

Creating a Custom Post Type in a Plugin:

function create_custom_post_type() {
    register_post_type('custom_post_type', array(
        'public' => true,
        'label' => 'Custom Post Type',
    ));
}
add_action('init', 'create_custom_post_type');

Adding an Admin Menu Page:

function custom_menu_page() { add_menu_page('Custom Page', 'Custom Menu', 'manage_options', 'custom-page', 'custom_page_callback', 'dashicons-admin-generic', 6); } add_action('admin_menu', 'custom_menu_page'); function custom_page_callback() { // Content of the custom page }

Custom Dashboard Widget:

function custom_dashboard_widget() { wp_add_dashboard_widget('custom_dashboard_widget', 'Custom Widget', 'custom_dashboard_widget_callback'); } add_action('wp_dashboard_setup', 'custom_dashboard_widget'); function custom_dashboard_widget_callback() { // Widget content }

Creating a Custom Cron Job:

function custom_cron_job() { // Cron job logic } add_action('wpse_custom_cron', 'custom_cron_job'); if (!wp_next_scheduled('wpse_custom_cron')) { wp_schedule_event(time(), 'daily', 'wpse_custom_cron'); }

Customizing the Login Logo:

function custom_login_logo() {
    echo '<style type="text/css">h1 a { background-image: url('.get_template_directory_uri().'/images/custom-logo.png) !important; }</style>';
}
add_action('login_head', 'custom_login_logo');

Similar Posts