Skip to content

Instantly share code, notes, and snippets.

View taotiwordpress's full-sized avatar

taotiwordpress

View GitHub Profile
@taotiwordpress
taotiwordpress / api.php
Created August 24, 2020 17:43
[apit insert posts] link to api and create posts in CPT #api #php
<?php
function insert_from_api() {
if(isset($_GET['input'])) {
// API URL
$url = '';
// Create a new cURL resource
@taotiwordpress
taotiwordpress / helper-functions.php
Last active August 26, 2020 17:31
[lorium ipson populate acf text field] function to populate acf fields #php #acf
function field_with_ipsum_fallback( $text ) {
if ( ! empty( $text ) ) {
echo $text;
} else {
echo 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque pellentesque risus vel venenatis faucibus. Nam id pharetra nisl. Nullam viverra eu nisi vel placerat. Donec faucibus blandit dictum';
}
}
function heading_with_ipsum_fallback( $heading ) {
if ( ! empty( $heading ) ) {
echo $heading;
@taotiwordpress
taotiwordpress / textBlock.php
Created August 26, 2020 19:02
[text-block] Page builder text block module #pagebuilder
<?php
namespace Modules;
use Timber;
### Example usage
// $args = [
// 'text_block' => get_sub_field('text_block'),
// ];
// $new_module = new TextBlock($args);
// $new_module->render();
@taotiwordpress
taotiwordpress / accordion.js
Last active August 26, 2020 19:15
[accordion block] accordion page builder #pagebuilder #php
var $toggle = jQuery('.accordion-toggle'),
$accordionText = jQuery('.accordion-descriptionText');
$toggle.on('change', function() {
jQuery(this).parent().find( $accordionText ).toggleClass('active');
});
@taotiwordpress
taotiwordpress / share.php
Created August 26, 2020 19:12
[share functionality] simple share functionality snippet #html #php
<a href="https://www.facebook.com/sharer.php?u=<?php the_permalink();?>">
<svg xmlns="http://www.w3.org/2000/svg" width="8" height="15" viewBox="0 0 8 15">
<path id="Color_Overlay" data-name="Color Overlay"
d="M2.357,15V8.166H0V5.493H2.363V3.525A3.255,3.255,0,0,1,5.885,0,19.38,19.38,0,0,1,8,.107V2.493H6.557c-1.141,0-1.361.525-1.361,1.3v1.7H7.92L7.566,8.166H5.2V15Z"
fill="#4a3b03" />
</svg>
</a>
<a href="https://twitter.com/share?url=<?php the_permalink();?>&text=<?php the_title();?>">
<svg xmlns="http://www.w3.org/2000/svg" width="17" height="15" viewBox="0 0 17 15">
<path id="Color_Overlay" data-name="Color Overlay"
@taotiwordpress
taotiwordpress / options.php
Last active March 4, 2022 21:49
[Add options page functionality (and for custom post types )] #php #acf #acf-options #options-page
if ( function_exists( 'acf_add_options_page' ) ) {
/**
* Example: Single 'Theme Settings' page, with children
*
* These only create the pages, which must be then populated via custom ACF fields.
* This setup creates a 'parent' ACF config page and sub-pages.
*/
acf_add_options_page(
array(
'page_title' => 'Theme General Settings',
@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];
@taotiwordpress
taotiwordpress / button.html
Last active August 12, 2021 21:26
[Back to top button]
<a href="#" id="back-to-top"></a>
@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 / 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(); ?>">