Skip to content

Instantly share code, notes, and snippets.

View phpbits's full-sized avatar
🎯
Focusing

Jeffrey Carandang phpbits

🎯
Focusing
View GitHub Profile
@import "./blocks/container/style.scss";
.wp-block[data-type="custom-block/container"] {
> .block-editor-block-list__block-edit {
padding: 30px 50px;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}
}
.entry-content {
.wp-block-custom-block-container {
padding: 30px 50px;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}
}
<?php
/**
** Add custom scripts
**/
add_action( 'wp_enqueue_scripts', 'my_custom_scripts' );
function my_custom_scripts(){
wp_enqueue_script( 'custom_js', plugins_url( 'js/custom.js', __FILE__ ), array(), '1.0.0', true );
wp_register_style( 'custom_css', plugins_url( 'style.css', __FILE__ ), false, '1.0.0', true );
wp_enqueue_style ( 'custom_css' );
<?php
/**
** Add custom body class
**/
add_filter('body_class', 'custom_body_class');
function custom_body_class( $classes ) {
$classes[] = 'new-body-class';
return $classes;
}
?>
<?php
/**
* Plugin Name: My Custom Shortcodes
* Plugin URI: https://wordpress.org/plugins/my-custom-shortcodes/
* Description: Custom shortcode for plugin development talk
* Version: 1.0
* Requires at least: 5.2
* Requires PHP: 7.2
* Author: Jeffrey Carandang
* Author URI: https://jeffreycarandang.com/
@phpbits
phpbits / gist.html
Created November 19, 2019 18:55
CoBlocks Gist Block Demo.
CoBlocks Github Gist Block Demo.
import { useSelect } from '@wordpress/data';
/**
* My Custom Block
*/
const MyCustomBlock = () => {
const META_KEY = 'custom_post_meta';
const meta = useSelect((select) =>
select('core/editor').getEditedPostAttribute('meta')
);
@phpbits
phpbits / saveMeta.js
Created June 2, 2023 09:18
Modifying, Editing, and Saving Post Meta Values in the Gutenberg Block Editor: https://jeffreycarandang.com/how-to-enable-read-and-update-post-meta-in-the-wordpress-block-editor-gutenberg/(opens in a new tab)
import { __ } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';
import { PanelBody, PanelRow, TextControl } from '@wordpress/components';
import { InspectorControls } from '@wordpress/block-editor';
/**
* My Custom Block
*/
const MyCustomBlock = () => {
const META_KEY = 'custom_post_meta';
const { __ } = wp.i18n;
const { useSelect } = wp.data;
const { store: blockEditorStore } = wp.blockEditor;
/**
* Block Edit Component
*/
const Edit = (props) => {
const { clientId } = props;
const innerBlocks = useSelect(