Skip to content

Instantly share code, notes, and snippets.

@yuliyang
yuliyang / functions.php
Created December 28, 2021 07:56
[WordPress] Disable Block Widget (after WordPress 5.8)
<?php
function ching_disable_block_widget() {
remove_theme_support(‘widgets-block-editor’);
}
add_action(‘after_setup_theme’, ‘ching_disable_block_widget’);
@yuliyang
yuliyang / functions.php
Last active December 27, 2021 03:47
[WordPress] Shortcodes
<?php
add_action( 'init', 'ching_shortcode' );
function ching_shortcode() {
// Usage: [ching-shortcode text="Hello World!"]
add_shortcode( 'ching-shortcode', 'ching_test_shortcode' );
function ching_test_shortcode( $atts ) {
$atts = shortcode_atts( array(
'text' => 'Hello World!',
@yuliyang
yuliyang / functions.php
Created December 20, 2021 11:40
[Gravity Forms] Custom Merge Tags
<?php
add_filter('gform_custom_merge_tags', 'ching_custom_merge_tags', 10, 4);
function ching_custom_merge_tags( $merge_tags, $form_id, $fields, $element_id ) {
$merge_tags[] = array('label' => 'Open Present', 'tag' => '{open_present}');
return $merge_tags;
}
add_filter('gform_replace_merge_tags', 'ching_replace_merge_tags', 10, 3);
function ching_replace_merge_tags( $text, $form, $entry ) {
if ( strpos( $text, '{open_present}' ) ) {
$text = str_replace( '{open_present}', 'Here it is!', $text );
@yuliyang
yuliyang / functions.php
Last active November 8, 2021 13:31
[WooCommerce] Cart Total Shortcode
<?php
// Allow shortcode in nav items
add_filter('wp_nav_menu_items', 'do_shortcode');
// [cart-total]
add_shortcode( 'cart-total', 'ching_shortcode_woo_cart_total' );
function ching_shortcode_woo_cart_total(){
$total = WC()->cart->total;
return '<span>'.wc_price($subtotal).'</span>';
}
@yuliyang
yuliyang / functions.php
Created October 18, 2021 03:48
[Toolset] Hide Trash Button
<?php
// hide toolset trash button for relationship CPT
add_action('admin_head', 'ching_admin_css');
function ching_admin_css() {
echo '<style>
.wp-admin.post-type-recipe .toolset-listing-wrapper .wp-list-table .row-actions .delete {
display: none;
}
</style>';
}
@yuliyang
yuliyang / functions.php
Created October 18, 2021 03:35
[WooCommerce] Add Continue Shopping
<?php
// Add continue shopping
// add_action( 'woocommerce_before_checkout_form', 'ching_back_to_store' );
add_action('woocommerce_cart_coupon', 'ching_back_to_store');
// add_action( 'woocommerce_cart_actions', 'ching_back_to_store' );
function ching_back_to_store() { ?>
<a class="button wc-backward" href="<?php echo esc_url( wc_get_page_permalink( 'shop' ) ); ?>"> <?php _e( '繼續購物', 'woocommerce' ) ?> </a>
<?php
}
@yuliyang
yuliyang / functions.php
Last active October 18, 2021 03:35
[WooCommerce] Add/Rename Product Tabs
<?php
// Add product tabs
add_filter( 'woocommerce_product_tabs', 'ching_woo_new_tab' );
function ching_woo_new_tab( $tabs ) {
// rename description tab title
$tabs['description']['title'] = __( '商品特色' );
// add the new tab - specs
$tabs['specs'] = array(
'title' => __( '商品規格', 'woocommerce' ),
@yuliyang
yuliyang / functions.php
Last active October 18, 2021 03:30
[WooCommerce] Add Endpoint (YITH wishlist for example)
<?php
// add wishlist endpoint
function ching_add_wishlist_endpoint() {
add_rewrite_endpoint( 'wishlist', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'ching_add_wishlist_endpoint' );
function ching_wishlist_query_vars( $vars ) {
$vars[] = 'wishlist';
@yuliyang
yuliyang / functions.php
Created July 7, 2020 13:53
[WordPress] Enqueue Google Fonts
<?php
function ching_add_google_fonts() {
wp_enqueue_style( 'ching-google-fonts', 'fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@300;400;500;700&family=Noto+Serif+TC:wght@300;400;500;600;700&display=swap', false );
}
add_action( 'wp_enqueue_scripts', 'ching_add_google_fonts' );
@yuliyang
yuliyang / gist:52805d28c63f30a249268c9f1bfb2f07
Created July 25, 2019 08:16
[WP Rocket] Advanced Options - Prefetch DNS requests
//maps.googleapis.com
//maps.gstatic.com
//fonts.googleapis.com
//fonts.gstatic.com
//ajax.googleapis.com
//apis.google.com
//google-analytics.com
//www.google-analytics.com
//ssl.google-analytics.com
//youtube.com