Skip to content

Instantly share code, notes, and snippets.

View taotiwordpress's full-sized avatar

taotiwordpress

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / image.php
Created August 19, 2021 01:07
[picture image] Responsive image, using thumbnail. #responsive #image #thumbnail #php
<?php
$photoBannerId = get_post_thumbnail_id();
$photoBannerUrlBase = wp_get_attachment_image_src($photoBannerId, 'listing')[0];
$photoBannerUrlBaseSmall = wp_get_attachment_image_src($photoBannerId, 'listing-small')[0];
if ($photoBannerId) { ?>
<picture>
<source media="(max-width: 1023px)" srcset="<?= esc_attr($photoBannerUrlBase) ?>">
<source media="(min-width: 1024px)" srcset="<?= esc_attr($photoBannerUrlBaseSmall) ?>">
<source srcset="<?= esc_attr($photoBannerUrlBaseSmall) ?>">
<img src="<?= esc_attr($photoBannerUrlBaseSmall) ?>" alt="Photo of <?php the_title(); ?>">
@taotiwordpress
taotiwordpress / dashboard.js
Created August 17, 2021 21:37
[acf page builder preview] then add preview folder to inc/acf/ #acf #dashboard #admin
// Add ACF Content Blocks preview images.
jQuery(document).ready(function ($) {
if (typeof acf !== 'undefined') {
acf.addAction('load', () => {
$('.tmpl-popup').each((_, popup) => {
const regex = /data-layout="(.+?)".*?>/g;
const replace = `$&<img src="${taoti_admin_js.acfPreviewUrl}$1.jpg">`;
const result = $(popup).html().replace(regex, replace);
$(popup).html(result);
});
@taotiwordpress
taotiwordpress / button.html
Last active August 12, 2021 21:26
[Back to top button]
<a href="#" id="back-to-top"></a>
@taotiwordpress
taotiwordpress / header.php
Created July 29, 2021 20:05
[pantheon conditional google analytics] #pantheon #google
<?php # Live-specific configs
if ( in_array( $_ENV['PANTHEON_ENVIRONMENT'], array( 'live' ) ) ) { ?>
<script>
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];