Skip to content

Instantly share code, notes, and snippets.

View benpearson's full-sized avatar

Ben Pearson benpearson

  • Melbourne, Australia
View GitHub Profile
@benpearson
benpearson / _table-mixins.scss
Created January 9, 2025 21:33
Table core block: Styles
/* ------------------------------------------------------------ *\
Mixins: Table core block
Included in frontend and admin styles.
\* ------------------------------------------------------------ */
@mixin wp-block-table {
@include blocks-core__margin-vertical__large;
// font-weight: 400;
@benpearson
benpearson / _pullquote-mixins.scss
Created January 9, 2025 21:31
Pullquote core block: Styles
/* ------------------------------------------------------------ *\
Mixins: Pullquote core block
Included in frontend and admin styles.
\* ------------------------------------------------------------ */
@mixin wp-block-pullquote {
@include blocks-core__margin-vertical__large;
border: none; // core style reset
@benpearson
benpearson / _embed-admin.scss
Created January 9, 2025 21:28
Embed core block: Styles
/* ------------------------------------------------------------ *\
Core block: Embed
Editor styles only
\* ------------------------------------------------------------ */
.wp-block-embed {
@include wp-block-embed;
}
@benpearson
benpearson / _search-results.scss
Created January 9, 2025 21:24
Search results: Styles
/* ------------------------------------------------------------ *\
Search results
\* ------------------------------------------------------------ */
.search-results__wrap {
@include breakpoint-down(mobile) {
margin-top: 15px;
}
@benpearson
benpearson / all.php
Last active January 9, 2025 11:06
WordPress: Schema examples
<script type="application/ld+json">
{
"@context": "https://schema.org",
<?php
$post_id = dt_get_the_ID();
if ( is_singular( 'ei_location' ) ) {
get_template_part('components/schema/location');
}
elseif ( is_singular( 'ei_job' ) ) {
@benpearson
benpearson / query.php
Created January 9, 2025 10:50
WordPress: Exclude posts based on ACF true/false field
$query_args = [
'post_type' => ['dt_project'],
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'meta_query' => [
'relation' => 'OR',
[
'key' => 'exclude_project',
'compare' => 'NOT EXISTS',
@benpearson
benpearson / excerpts.php
Created January 9, 2025 08:15
WordPress: Excerpt helpers
function dt_custom_excerpt_length($length)
{
global $post;
if ($post->post_type == 'post') {
return 18; // words
}
}
// add_filter( 'excerpt_length', 'dt_custom_excerpt_length', 999 );
@benpearson
benpearson / page-templates.php
Created January 9, 2025 08:12
Wordpress: Full width template conditional helper
<?php
/**
* Helpers: Page Templates
*/
function dt_is_full_width_template($post_id) {
if (!$post_id) {
return false;
@benpearson
benpearson / video.php
Created January 9, 2025 08:09
Wordpress: Get YouTube thumbnail URL
<?php
/**
* Helpers: Videos
*/
function dt_get_youtube_thumbnail_url($youtube_video_id)
{
return $youtube_video_id
? 'https://img.youtube.com/vi/' . $youtube_video_id . '/0.jpg' // get first thumbnail from youtube
@benpearson
benpearson / password-protection.php
Created January 9, 2025 07:17
WordPress: Password protected content helpers
<?php
/**
* Helpers: Password protected content
*/
/**
* Remove "Protected:" prefix from the title of password protected posts
*/
function dt_remove_protected_prefix_from_titles($var, $post)