Skip to content

Instantly share code, notes, and snippets.

View yoren's full-sized avatar

Yoren Chang yoren

View GitHub Profile
@yoren
yoren / gist:8667719
Created January 28, 2014 13:35
Whitelist you IPs in .htaccess in WordPress
<Files wp-login.php>
Order deny,allow
Deny from All
Allow from 123.123.123.123 111.111.111.111
</Files>
@yoren
yoren / gist:8667867
Created January 28, 2014 13:42
Blacklist suspicious IPs in .htaccess in WordPress
<Files wp-login.php>
order deny,allow
deny from 123.123.123.123
allow from all
</Files>
filter:
excluded_paths:
- 'languages/*'
- 'lib/*'
- 'tests/*'
paths:
- 'inc/*'
- '*'
tools:
php_cpd:
@yoren
yoren / functions.php
Created March 5, 2014 14:27
Exclude Subcategories in a Loop
<?php
function wpse_filter_child_cats( $query ) {
if ( $query->is_category ) {
$queried_object = get_queried_object();
$child_cats = (array) get_term_children( $queried_object->term_id, 'category' );
if ( ! $query->is_admin )
//exclude the posts in child categories
@yoren
yoren / 0_reuse_code.js
Created May 31, 2014 15:09
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@yoren
yoren / admin.js
Last active August 29, 2015 14:03
The anatomy of Quick Add Child
(function ( $ ) {
"use strict";
var post_ID = $('#post_ID').val(),
parent_id = ( '' == $('#parent_id').val() ) ? 0 : $('#parent_id').val(),
addNew = $('.add-new-h2'),
html = '';
html += ' <a id="add_new_sibling" href="post-new.php?post_type=' + typenow + '&parent_id=' + parent_id + '" class="add-new-h2" target="_blank">' + quick_add_child_js_params.add_new_sibling + '</a>';
html += '<a id="add_new_child" href="post-new.php?post_type=' + typenow + '&parent_id=' + post_ID + '" class="add-new-h2" target="_blank">' + quick_add_child_js_params.add_new_child + '</a>';
@yoren
yoren / functions.php
Last active August 29, 2015 14:05
Add icons to wp_list_categories
<?php
function my_list_categories( $output, $args ) {
$pattern = '/(<a.*?>)/';
$replacement = '$1<i class="ico-my"></i> ';
return preg_replace( $pattern, $replacement, $output );
}
add_filter( 'wp_list_categories', 'my_list_categories', 10, 2 );
@yoren
yoren / functions.php
Last active February 17, 2019 20:03
Return the right previous_post_link / next_post_link when change posts order
<?php
function my_previous_post_where() {
global $post, $wpdb;
return $wpdb->prepare( "WHERE p.menu_order < %s AND p.post_type = %s AND p.post_status = 'publish'", $post->menu_order, $post->post_type);
}
add_filter( 'get_previous_post_where', 'my_previous_post_where' );
@yoren
yoren / functions.php
Created October 28, 2014 12:26
Change default style number in WordPress
<?php
function sp_wp_default_styles($styles)
{
//use our app version constant
$styles->default_version = SCHOOLPRESS_VERSION;
}
add_action("wp_default_styles", "sp_wp_default_styles");
@yoren
yoren / functions.php
Last active March 13, 2016 00:02
Enqueue AngularJS into your theme
<?php
function my_scripts() {
wp_enqueue_script(
'angularjs',
get_stylesheet_directory_uri() . '/bower_components/angular/angular.min.js'
);
wp_enqueue_script(