Skip to content

Instantly share code, notes, and snippets.

@zackpyle
zackpyle / wp-customizer-css.php
Created July 22, 2024 14:26
Add your own CSS to style the Customizer itself
<?php
function custom_customizer_styles() {
$custom_css = "
.preview-mobile #customize-preview iframe,
.preview-mobile .wp-full-overlay-main{
width: 375px;
height: 667px;
}
@zackpyle
zackpyle / acf-horizontal-repeater.css
Created July 18, 2024 19:42
CSS to display ACF repeater horizontally
/*
* ACF "repeat-horizontal" class, display repeaters in horizontal columns
*/
.repeat-horizontal .acf-repeater tbody {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
/* Change flex-basis to like 20% if you want to limit number of items per row */
.repeat-horizontal .acf-repeater tr.acf-row:not(.acf-clone) {
@zackpyle
zackpyle / wp-more-bb.php
Last active July 16, 2024 18:49
Use WP's <!--more--> in Beaver Builder's text module like <!--more Keep on reading!--> to reveal content after clicking
<?php
add_filter( 'fl_builder_render_module_content', function( $content, $module ) {
if ( $module instanceof FLRichTextModule && strstr( $content, '<!--more' ) ) {
$content = str_replace( '<div class="fl-rich-text">', '', $content );
$content = preg_replace( '#</div>$#', '', $content );
$parts = get_extended( $content );
$main = balanceTags( $parts['main'], true );
$main = preg_replace( '/<([^<\/>]*)>([\s]*?|(?R))<\/\1>/imsU', '', $main );
@zackpyle
zackpyle / rename-posts-to-articles.php
Created July 13, 2024 12:32
Rename Posts post type to Articles
<?php
add_action('init', function() {
$post_type = get_post_type_object('post');
if ($post_type) {
$labels = $post_type->labels;
$labels->name = 'Articles';
$labels->singular_name = 'Article';
$labels->add_new = 'Add Article';
@zackpyle
zackpyle / preload-hero-bg-image.php
Last active July 16, 2024 14:33
Using Perfmatters filter to preload hero image. Hero image is defined using ACF either as by default, the Featured Image (_thumbnail_id), or if you want a separate hero image from your featured image, then a Hero Image Override field
<?php
add_filter('perfmatters_preloads', function($preloads) {
if (function_exists('get_field') && isset($GLOBALS['post'])) {
$post = $GLOBALS['post'];
// Check hero_options - bail early if we're not using a hero image
$hero_options = get_field('hero_options', $post->ID);
if ($hero_options === 'hero-default' || $hero_options === 'hero-small') {
// Check for hero image override
@zackpyle
zackpyle / floating-label-fluent-forms.css
Last active July 10, 2024 18:02
CSS for Floating Labels using Fluent Forms
/* Floating Labels */
.ff-el-group {
position: relative;
}
.ff-el-form-control::placeholder {
color: transparent !important;
}
.fluentform .ff-el-input--label {
@zackpyle
zackpyle / _scroll-shadow.js
Last active June 24, 2024 20:06
Add an inset shadow to a a scrollable div, and remove the shadow once you reach the bottom of the scroll
jQuery(document).ready(function($) {
// Add shadow class to containers and remove when you scroll to the bottom
const $recurringEventsLists = $('.recurring-events-list');
function checkScrollAndHeight() {
const $this = $(this);
// Check if the content height is greater than the max-height of the container
if ($this.prop('scrollHeight') > $this.height()) {
@zackpyle
zackpyle / team-bootstrap-modal.html
Created June 21, 2024 14:47
Team CPT + Bootstrap Modal
<div class="team-member wrapcenter">
<div class="headshot-wrapper">
<img class="team-headshot" src="[wpbb post:featured_image size='medium' display='url']">
<!-- Button trigger modal -->
<button type="button" aria-label="Read more about [wpbb post:title]" class="modal-btn" data-toggle="modal" data-target="#[wpbb post:slug]">
Learn More <span class="sr-only">about [wpbb post:title]</span>
</button>
</div>
<h3 class="team-name">[wpbb post:title]</h3>
<p class="team-position">[wpbb post:acf type='text' name='team_position']</p>
@zackpyle
zackpyle / first-name-shortcode.php
Created June 5, 2024 19:10
Get First Name (aka first word in page title)
<?php
add_shortcode( 'first_name', 'get_first_name' );
function get_first_name() {
$title = get_the_title();
$full_name_seperate = explode( ' ', $title );
return $full_name_seperate[0];
}
@zackpyle
zackpyle / fluent-forms-radio-button-acf-relationship.php
Last active June 5, 2024 19:33
Set the value of a Fluent Form radio field with an ACF Relationship field from the current page
<?php
add_filter('fluentform/rendering_field_data_input_radio', function ($data, $form) {
if ($form->id != 3) { // Form ID
return $data;
}
// Set which field to do this on
if (\FluentForm\Framework\Helpers\ArrayHelper::get($data, 'attributes.name') != 'FF_FORM_FIELD_NAME') { // Form field name here
return $data;