Skip to content

Instantly share code, notes, and snippets.

View yoren's full-sized avatar

Yoren Chang yoren

View GitHub Profile

Zip excluding specific directories

Exclude .git file and node_modules directory

$ zip -r9 [target_file] [source_file] -x *.git* node_modules/\*

Exclude .git file and files in node_modules directory, but keep node_modules directory

$ zip -r9 [target_file] [source_file] -x *.git* node_modules/**\*
View gist:9a84d039b42c4f6cd9c1bd2c821e32bd
### Keybase proof
I hereby claim:
* I am yoren on github.
* I am yoren ( on keybase.
* I have a public key whose fingerprint is 87BF F3DA 7D0C 3BE8 1151 C583 8F39 C153 6FC8 D42C
To claim this, I am signing this object:
yoren / functions.php
Created October 25, 2016 09:23
Get terms by custom post types and taxonomy
View functions.php
* my_terms_clauses
* filter the terms clauses
* @param $clauses array
* @param $taxonomy string
* @param $args array
yoren / functions.php
Last active April 20, 2020 15:38
Changing arguments for the built-in taxonomies in WordPress
View functions.php
function ofix_register_tax_args( $args, $taxonomy, $object_type ) {
if ( 'link_category' === $taxonomy ) {
$args['public'] = true;
$args['query_var'] = true;
return $args;
yoren / 1fix-switch-theme-on-certain-pages.php
Created August 10, 2016 08:27
WordPress tiny plugin - Switch theme on certain pages
View 1fix-switch-theme-on-certain-pages.php
* @package One_Fix_Switch_Theme
* @version 1.0
Plugin Name: One Fix Switch Theme
Plugin URI:
Description: Switch theme on certain pages.
Author: Yoren Chang
yoren / functions.php
Last active February 29, 2016 07:50
Using meta_query With WP API V2
View functions.php
function my_allow_meta_query( $valid_vars ) {
$valid_vars = array_merge( $valid_vars, array( 'meta_key', 'meta_value', 'meta_query' ) ); // Omit meta_key, meta_value if you don't need them
return $valid_vars;
add_filter( 'rest_query_vars', 'my_allow_meta_query' );
yoren / nginx.conf
Last active March 13, 2016 00:16
Proxy WP content images for your local server
View nginx.conf
// Source:
// But if you need an nginx flavor
// Put this in your server block
rewrite ^/wp-content/uploads(.+)$$1 last;
yoren / functions.php
Last active March 21, 2023 23:15
Parent Post From Another Post Type And A New URL Structure In WordPress
View functions.php
// Flush rewrite rules after switch theme
function my_rewrite_flush() {
add_action( 'after_switch_theme', 'my_rewrite_flush' );
// A little help so we can get the stylesheet from parent theme
// Remove line 10-19 if this is not a child theme
function my_enqueue_styles() {
yoren / extra.php
Last active August 3, 2016 19:35
Cookie Authentication In A AngularJS WordPress Theme
View extra.php
// The following function is from:
* Check for errors when using cookie-based authentication.
* WordPress' built-in cookie authentication is always active
* for logged in users. However, the API has to check nonces
* for each request to ensure users are not vulnerable to CSRF.
* @global mixed $wp_rest_auth_cookie
yoren / functions-1.php
Last active February 18, 2016 04:17
Upgrading Your AngularJS Theme To Work With WP API V2
View functions-1.php
function my_rest_prepare_post( $data, $post, $request ) {
$_data = $data->data;
$thumbnail_id = get_post_thumbnail_id( $post->ID );
$thumbnail = wp_get_attachment_image_src( $thumbnail_id );
$_data['featured_image_thumbnail_url'] = $thumbnail[0];
$data->data = $_data;