Skip to content

Instantly share code, notes, and snippets.

@pento
pento / stars-block.js
Last active January 4, 2022 14:00
Gutenberg Stars Block
( function( blocks, element ) {
var el = element.createElement;
function Stars( { stars } ) {
return el( 'div', { key: 'stars' },
'★'.repeat( stars ),
( ( stars * 2 ) % 2 ) ? '½' : '' );
}
blocks.registerBlockType( 'stars/stars-block', {
@wpscholar
wpscholar / smooth-scroll.jquery.js
Created March 15, 2016 15:50
Implement smooth scroll for all internal page links.
// Smooth Scroll
$('a[href*="#"]:not([href="#"])').click(function () {
var target = $(this.hash);
if (target.length) {
var isInternalLink = new RegExp('/' + window.location.host + '/');
if (isInternalLink.test(this.href)) {
$('html, body').animate({scrollTop: target.offset().top}, 1000);
return false;
}
}
@codearachnid
codearachnid / filter_gf_select_optgroup.php
Last active July 16, 2024 15:51
Add the optgroup ability to Gravity Forms default select field.
/**
* Filter Gravity Forms select field display to wrap optgroups where defined
* USE:
* set the value of the select option to `optgroup` within the form editor. The
* filter will then automagically wrap the options following until the start of
* the next option group
*/
add_filter( 'gform_field_content', 'filter_gf_select_optgroup', 10, 2 );
function filter_gf_select_optgroup( $input, $field ) {