Skip to content

Instantly share code, notes, and snippets.

View taotiwordpress's full-sized avatar

taotiwordpress

View GitHub Profile
@taotiwordpress
taotiwordpress / date.php
Created August 19, 2021 03:01
[convert format of acf date field] #acf #php #date
$date = get_field('date_published', false, false);
$event_date = new DateTime($date);
$new_time = $event_date->format('ga');
$first_date = $event_date->format('F j, Y');
<?= $first_date; ?>
@taotiwordpress
taotiwordpress / snippet.php
Last active August 20, 2021 17:47
[Change Gravity forms fields markup] For fancy radios and checkboxes
<?php
add_filter( 'gform_field_choice_markup_pre_render', function ( $choice_markup, $choice, $field, $value ) {
if ( $field->get_input_type() == 'radio') {
return str_replace( "<label", "<span class='faux-radio'></span><label", $choice_markup );
}
if ( $field->get_input_type() == 'checkbox') {
return str_replace( "<label", "<span class='faux-checkbox'></span><label", $choice_markup );
}
@taotiwordpress
taotiwordpress / breadcrumbs-template.php
Created August 20, 2021 17:50
[Yoast Breadcrumbs]
<?php
if ( function_exists('yoast_breadcrumb') && is_front_page() == false ){
yoast_breadcrumb( '<p id="breadcrumbs">','</p>' );
}
?>
@taotiwordpress
taotiwordpress / custom-meta-boxes.php
Last active August 24, 2021 14:01
API control for rebuilding WordPress admin-editor metaboxes #wordpress #metabox #tags #category
<?php
### This file provides an API for rebuilding metaboxes
### See https://rudrastyh.com/wordpress/tag-metabox-like-categories.html
### for inspiration on content.
### See wp-admin/meta-boxes.php for source-code.
// add_action( 'admin_menu', 'taoti_post_taxonomy_metabox_remove' );
// add_action( 'admin_menu', 'taoti_add_autosorting_taxonomy_metabox' );
@taotiwordpress
taotiwordpress / cli-cheatsheet.md
Created August 24, 2021 13:43
Note Cheatsheets

Command Cheat Sheets

terminus

  • Site List: terminus taoti:site:list
  • Multidev
    • Create: terminus multidev:create --

WP Commands

@taotiwordpress
taotiwordpress / create-content.php
Created August 26, 2021 17:01
Programmatically Generate Post with ACF content #acf #wordpress
<?php
/**
* Create Post Example
*
*. Note: See https://www.advancedcustomfields.com/resources/update_field/ for notes.
*/
// Create new post.
$post_data = array(
@taotiwordpress
taotiwordpress / svg.php
Created August 26, 2021 22:27
[allow svg upload] function to make the media library support svgs #svg #image #wordpress
function cc_mime_types($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
@taotiwordpress
taotiwordpress / anchor.php
Last active March 4, 2022 16:22
[ACF Anchor id] Add Anchor link to acf page builder block #acf #php #wordpress #flex-content #deprecated
<?php
/**
* Note: If using Timber, a generated anchor is avaiable via {{ block.id }}
* This approach requires creating a custom 'anchor_id' field and/or using PHP to custom-generate one.
*/
$anchor_id = get_sub_field( 'anchor_id' );
?>
@taotiwordpress
taotiwordpress / column.php
Created September 9, 2021 01:42
[show thumbnail in CPT] Show Custom Post Type thumbnail in admin column #CPT #admin
function custom_columns( $columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'featured_image' => 'Image',
'title' => 'Title',
'comments' => '<span class="vers"><div title="Comments" class="comment-grey-bubble"></div></span>',
'date' => 'Date'
);
return $columns;
}
@taotiwordpress
taotiwordpress / button-shortcode.php
Last active September 22, 2021 16:34
[button shortcode] #php #wysiwyg #shortcode
<?php
/**
* Custom ShortCode for WYSIWYG Buttons.
*
* @todo Convert to allow for <button> and identifying the need for role='button'.
*/
function custom_button_shortcode( $atts, $content = null ) {
// shortcode attributes
$atts = shortcode_atts(