Skip to content

Instantly share code, notes, and snippets.

View taricco's full-sized avatar

taricco

  • Seattle, WA
View GitHub Profile
// Add taxonomy filter dropdowns to the Resources CPT admin page
function wsv_resources_category_filter() {
global $typenow;
if ($typenow == 'resources') {
$taxonomies = array('resource-type');
if (!empty($taxonomies)) {
foreach ($taxonomies as $taxonomy) {
$selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
$info_taxonomy = get_taxonomy($taxonomy);
wp_dropdown_categories(array(
/*** Load editor notice for Video CPT
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
function wsv_video_cpt_notice_script() {
// Ensure we are on the admin screen to prevent errors on the front end
if (is_admin()) {
// Get the current screen object
$screen = get_current_screen();
// Check if the current screen is for the 'video' post type
if ($screen->post_type == 'video') {
/*** Set default editor content for Video CPT using a specific Local Pattern
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
function add_or_replace_content_with_gb_template_for_video_posts($data, $postarr) {
// Only target the 'video' post type
if ($data['post_type'] == 'video') {
// Define your gblocks_templates Post ID
$gb_template_post_id = 5593; // Replace 5501 with your actual gblocks_templates Post ID
// Get the content of the gblocks_templates post
$gb_template_post = get_post($gb_template_post_id);
/*** Custom function for making the /matchday/ URL redirect to the next upcoming match URL
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
add_action('template_redirect', 'redirect_to_next_match');
function redirect_to_next_match() {
if (is_page('matchday')) { // Check if the current page is /matchday/
$today = date('Ymd'); // Get today's date in ACF's preferred format.
$args = array(
'post_type' => 'match', // Your custom post type.
'posts_per_page' => 1, // We only need the next match.
'meta_key' => 'match_date', // The ACF field key for the match date.
/*** Custom function for posting a notice on the "Matchday" editing page
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
function wsv_matchday_notice_script() {
// Ensure we are on the admin screen to prevent errors on the front end
if (is_admin()) {
// Get the current screen object
$screen = get_current_screen();
// Check if the current screen is for editing a 'page'
if ($screen->post_type == 'page') {
/*** Custom template tag for styling an ACF date field
Tag format: {{dateformat.field_name|D M j}}
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
add_filter("render_block", "wsv_date_format_tags", 11, 2); // Note the priority is set to 11, to ensure it runs after tct_template_tags
function wsv_date_format_tags($block_content, $block) {
// Updated pattern to allow a broader range of characters in the format, including commas, spaces, and common date format characters
$pattern = "/{{dateformat\.([\w-]+)\|([,\w\s-]+)}}/";
$new_content = preg_replace_callback($pattern, function ($matches) {
https://www.toptal.com/designers/htmlarrows/symbols/
Right Arrow - ❯ - Use in CSS - content: "\276F";
Left Arrow - ❮- Use in CSS - content: "\276E";
Right Arrow - ➤ - Use in CSS - content: "\27A4";
Right Arrow - ➔ - Use in CSS - content: "\2794";
/*** Set default editor content for Video CPT using a specific Local Pattern
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
function add_or_replace_content_with_gb_template_for_video_posts($data, $postarr) {
// Only target the 'video' post type
if ($data['post_type'] == 'cpt_name') {
// Define your gblocks_templates Post ID
$gb_template_post_id = 123; // Replace 5501 with your actual gblocks_templates Post ID
// Get the content of the gblocks_templates post
$gb_template_post = get_post($gb_template_post_id);
/*** Set default editor content for CPT using a specific Synced Pattern
NOTE: This action will overwrite the post content every time the post is saved.
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
function add_or_replace_content_with_synced_pattern_for_video_posts($data, $postarr) {
// Only target the 'video' post type
if ($data['post_type'] == 'cpt_name') {
// Define your reusable block ID
$reusable_block_id = 123; // Replace 123 with your actual reusable block ID
// Prepare the reusable block content
.max-width-150 .acf-input .acf-image-uploader .image-wrap img {
max-width: 150px;
}
.max-width-300 .acf-input .acf-image-uploader .image-wrap img {
max-width: 300px;
}
.no-edit-acf .acf-input {
pointer-events: none;
cursor: not-allowed;
opacity: 0.3;