Skip to content

Instantly share code, notes, and snippets.

@yuliyang
yuliyang / functions.php
Last active May 21, 2024 04:30
[ WooCommerce ] Notice Message Shortcode
<?php
function dejavu_woocommerce_notice_shortcode($atts) {
ob_start();
?>
<div id="ds-wc-notices"></div>
<script type="text/javascript">
jQuery(document).ready(function($) {
var noticesContainer = $('.woocommerce-notices-wrapper');
if (noticesContainer.length) {
$('#ds-wc-notices').append(noticesContainer);
@yuliyang
yuliyang / functions.php
Created May 18, 2023 10:34
[ WooCommerce ] Remove featured image/first image from product gallery
<?php
// remove featured image from product gallery
add_filter('woocommerce_single_product_image_thumbnail_html', 'ds_remove_product_featured_image', 10, 2);
function ds_remove_product_featured_image($html, $attachment_id ) {
global $post, $product;
$featured_image = get_post_thumbnail_id( $post->ID );
if ( $attachment_id == $featured_image )
$html = '';
@yuliyang
yuliyang / functions.php
Last active March 29, 2023 05:43
[ WordPress ] Product category accordion + load inline SVG
<?php
// load inline SVG
function ds_load_inline_svg($filename, $class = 'ds-icon-svg')
{
// Add the path to your SVG directory inside your theme.
$svg_path = '/assets/img/svg/';
// Check the SVG file exists
if (file_exists(get_stylesheet_directory() . $svg_path . $filename)) {
$svg = '';
$svg .= '<div class="ds-icon ' . $class . '">';
@yuliyang
yuliyang / script.js
Created March 7, 2023 16:32
[ jQuery ] Scroll to anchor link and offset based on header height
(function ($) {
$("a[href*=\\#]:not([href=\\#])").click(function () {
if (
location.pathname.replace(/^\//, "") ==
this.pathname.replace(/^\//, "") ||
location.hostname == this.hostname
) {
var target = $(this.hash),
headerHeight = $("header#site-header").height() + 20;
@yuliyang
yuliyang / functions.php
Created January 9, 2023 13:01
[ WordPress Blocks ] Register blocks + custom number list style + respect list start number
<?php
if ( function_exists( 'register_block_style' ) ) {
register_block_style(
'core/list',
array(
'name' => 'ds-number',
'label' => __( 'Number List', 'dejavu' ),
'is_default' => false,
)
);
@yuliyang
yuliyang / elementor-html-widget-1.html
Last active January 10, 2023 13:12
[ Elementor ] Slick Slider + Elementor Loop Grid
<!-- add a HTML widget -->
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/[email protected]/slick/slick.css"/>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/[email protected]/slick/slick-theme.css"/>
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/[email protected]/slick/slick.min.js"></script>
<script>
jQuery(document).ready(function(){
jQuery('.ds-slick-slide .elementor-loop-container').slick({
centerMode: true,
centerPadding: '0',
slidesToShow: 3,
@yuliyang
yuliyang / functions.php
Created October 10, 2022 19:05
[ Blocksy ] Use custom social icons svg
<?php
add_filter('blocksy:social-box:dynamic-social-networks', function ($networks) {
$networks[] = [
'id' => 'facebook',
'name' => __('Facebook', 'blocksy'),
'icon' => '<svg
width="20px"
height="20px"
viewBox="0 0 20 20"
aria-hidden="true">
@yuliyang
yuliyang / functions.php
Created October 7, 2022 13:47
[ WooCommerce ] Single Product - add new/rename product info tab
<?php
// single product - add new tab
add_filter( 'woocommerce_product_tabs', 'dejavu_woo_new_tab' );
function dejavu_woo_new_tab( $tabs ) {
// rename default product tabs
$tabs[ 'description' ][ 'title' ] = '內容簡介';
$tabs[ 'additional_information' ][ 'title' ] = '其他資訊';
// display only when ACF custom fields is presented
@yuliyang
yuliyang / functions.php
Last active April 28, 2022 05:50
[ Gravity Forms ] When confirmation message is displayed, send Facebook Pixel custom tracking
<?php
add_action('wp_footer', 'ching_gf_fbq' );
function ching_gf_fbq() {
// if show code on certain page
// if( ! is_page(123) )
// return;
?>
<script>
jQuery(document).ready(function(){
jQuery(document).on('gform_confirmation_loaded', function(event, formId) {
@yuliyang
yuliyang / fullArticle.html
Created January 26, 2022 08:22
[HelpScout] Turn H2 to Table of Content
<!-- Insert into your article (switch to HTML mode) -->
<section class="index-list">
<h4>In This Article</h4>
<ul id="toc"></ul>
</section>
<!-- This script will load all H2 headings in your article -->
<h2>I am a title!</h2>