Skip to content

Instantly share code, notes, and snippets.

@benplum
benplum / acf-blocks-testimonial.php
Created April 30, 2019 14:05
Block Editor - ACF Auto Block Template
<?php
$id = 'testimonial-' . $block['id'];
?>
<blockquote class="testimonial" id="<?php echo $id; ?>">
<p><?php echo $data['testimonial']; ?></p>
<cite>
<img src="<?php echo $data['avatar']['url']; ?>" alt="<?php echo $data['avatar']['alt']; ?>">
<span><?php echo $data['author']; ?></span>
</cite>
</blockquote>
@benplum
benplum / blocks-testimonial.php
Last active April 30, 2019 14:04
Block Editor - Block Template
<?php
$testimonial = get_field('testimonial');
$author = get_field('author');
$avatar = get_field('avatar');
$id = 'testimonial-' . $block['id'];
?>
<blockquote class="testimonial" id="<?php echo $id; ?>">
<p><?php echo $testimonial; ?></p>
<cite>
<?php
function editor_register_blocks() {
if ( function_exists('acf_register_block') ) {
acf_register_block(array(
'name' => 'testimonial',
'title' => __('Testimonial'),
'description' => __('A custom testimonial block.'),
'render_template' => 'blocks/testimonial.php',
'category' => 'formatting',
@benplum
benplum / editor-blocks.php
Last active May 8, 2022 15:01
Block Editor - Disable Core Blocks
<?php
function editor_disable_core_blocks() {
$blacklist = array(
// -- Common
'core/paragraph',
'core/image',
'core/heading',
'core/subhead',
'core/gallery',
@benplum
benplum / Paragraph Trim Functions
Last active August 29, 2015 13:59
Paragraph Trim Functions
function getFirstPP($html) {
$start = strpos($html, '<p');
$end = strpos($html, '</p>', $start);
$html = substr($html, $start, ($end - $start + 4));
return $html;
}
function splitFirstPP($html) {
$parts = explode("</p>", $html, 2);
$first = $parts[0] . "</p>";
@benplum
benplum / HTML5 Enabler
Created December 19, 2013 20:06
HTML5 Enabler
/* Pre-Define HTML5 Elements in IE */
(function(){ var els = "source|address|article|aside|audio|canvas|command|datalist|details|dialog|figure|figcaption|footer|header|hgroup|keygen|mark|meter|menu|nav|picture|progress|ruby|section|time|video".split('|'); for(var i = 0; i < els.length; i++) { document.createElement(els[i]); } } )();
@benplum
benplum / matchMedia - IE8
Last active February 1, 2017 21:37
matchMedia Polyfill w/ Listeners - IE8
// Modernizr style test
if (!(window.webkitMatchMedia || window.mozMatchMedia || window.oMatchMedia || window.msMatchMedia || window.matchMedia)) {
var root = document.getElementsByTagName( 'html' )[0];
root.className += ' no-matchmedia';
}
/*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license - IE8 VERSION! */
window.matchMedia = window.matchMedia || (function(doc, undefined){
var docElem = doc.documentElement,
@benplum
benplum / matchMedia - IE9
Last active April 16, 2020 15:57
matchMedia Polyfill w/ Listeners - IE9
// Modernizr style test
if (!(window.webkitMatchMedia || window.mozMatchMedia || window.oMatchMedia || window.msMatchMedia || window.matchMedia)) {
var root = document.getElementsByTagName( 'html' )[0];
root.className += ' no-matchmedia';
}
/*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas, David Knight. Dual MIT/BSD license */
window.matchMedia || (window.matchMedia = function() {
"use strict";
@benplum
benplum / Colored List Styles
Last active December 16, 2015 12:38
List styles colored differently then list text.
ol { counter-reset: item; }
ol li, ul li { color: black; list-style: none; }
ol li:before { color: red; counter-increment: item; content: counter(item) ". "; margin: 0 0 0 -20px; text-align: right; }
ul li:before { background: transparent; border: 1px solid red; border-radius: 100%; content: ''; display: block; float: left; height: 8px; margin: 10px 0 0 -20px; width: 8px; }
@benplum
benplum / PHP trim HTML
Created March 25, 2013 19:44
Random HTML string functions
function splitFirstP($html) {
$parts = explode("</p>", $html, 2);
$parts[0] = $parts[0]."</p>";
return $parts;
}
function splitCenterContent($html) {
$return = array();
$parts = explode("</p>", $html);
$middle = floor(count($parts) / 2) - 1;