Skip to content

Instantly share code, notes, and snippets.

@phpbits
Last active August 6, 2019 10:38
Show Gist options
  • Save phpbits/a820d90baf49032742c1090073dfce0f to your computer and use it in GitHub Desktop.
Save phpbits/a820d90baf49032742c1090073dfce0f to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: My Custom Block
* Plugin URI: https://github.com/phpbits/my-custom-block
* Description: Custom Gutenberg block for tutorial purposes
* Version: 1.0
* Author: Jeffrey Carandang
* Author URI: https://jeffreycarandang.com/
*
* @category Gutenberg
* @author Jeffrey Carandang
* @version 1.0
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
function my_custom_block_editor_assets(){
$url = untrailingslashit( plugin_dir_url( __FILE__ ) );
// Scripts.
wp_enqueue_script(
'my-custom-block-js', // Handle.
$url . '/build/index.js',
array( 'wp-blocks', 'wp-i18n', 'wp-element' )
);
// Styles.
wp_enqueue_style(
'my-custom-block-editor-css', // Handle.
$url . '/build/editor.css',
array( 'wp-edit-blocks' )
);
} // End function my_custom_block_editor_assets().
// Hook: Editor assets.
add_action( 'enqueue_block_editor_assets', 'my_custom_block_editor_assets' );
function my_custom_block_assets(){
$url = untrailingslashit( plugin_dir_url( __FILE__ ) );
wp_enqueue_style(
'my-custom-block-frontend-css', // Handle.
$url . '/build/style.css'
);
}
// Hook: Frontend assets.
add_action( 'enqueue_block_assets', 'my_custom_block_assets' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment