Skip to content

Instantly share code, notes, and snippets.

@shizhua
shizhua / js.js
Created June 8, 2016 08:40
SVG circular progress
$('#percent').on('change', function() {
var val = parseInt($(this).val());
var $circle = $('#svg #bar');
if (isNaN(val)) {
val = 100;
} else {
var r = $circle.attr('r');
var c = Math.PI * (r * 2);
@shizhua
shizhua / custom-sidebar.css
Last active June 4, 2016 04:13
Add unlimited sidebar in WordPress
.sidebar-info {
padding: 0 8px;
background-color: #fff;
border: 1px solid #e5e5e5;
-webkit-box-shadow: 0 1px 1px rgba(0,0,0,.04);
box-shadow: 0 1px 1px rgba(0,0,0,.04);
max-width: 300px;
display: none;
}
@shizhua
shizhua / update-notice.php
Created May 5, 2016 09:05
"update notice" for self-hosted themes
<?php
function pfun_update_notification ( $transient ) {
if ( empty( $transient->checked['pfun'] ) ) {
return $transient;
}
$url = 'http://ptheme.com/update.json';
//Send the request.
@shizhua
shizhua / custom-control.js
Last active July 16, 2021 09:11
Multiple checkbox customizer control
jQuery( document ).ready( function() {
/* === Checkbox Multiple Control === */
jQuery( '.customize-control-checkbox-multiple input[type="checkbox"]' ).on( 'change', function() {
checkbox_values = jQuery( this ).parents( '.customize-control' ).find( 'input[type="checkbox"]:checked' ).map(
function() {
return this.value;
}
@shizhua
shizhua / script-loaded.js
Created April 27, 2016 09:33 — forked from AllThingsSmitty/script-loaded.js
Check if any given script has loaded
var myScript = document.createElement('script');
myScript.src = 'http://code.jquery.com/jquery-2.1.4.min.js';
myScript.onload = function() {
console.log('jQuery loaded.');
};
document.body.appendChild(myScript);
@shizhua
shizhua / ajax.js
Last active April 27, 2017 04:59
Frontend Image Uploader in WordPress
( function( $ ) {
$('#upload_form').on('submit', function(e){
e.preventDefault();
var $this = $(this),
nonce = $this.find('#image_upload_nonce').val(),
images_wrap = $('#images_wrap'),
status = $('#status'),
formdata = false;
if ( $this.find('#images').val() == '' ) {
@shizhua
shizhua / pagination_custom_query.php
Created April 12, 2016 09:52
Fix pagination not working in custom query
<?php
// Define custom query parameters
$custom_query_args = array( /* Parameters go here */ );
// Get current page and append to custom query parameters array
$custom_query_args['paged'] = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
// If your page is a static front page, be sure to use page instead of paged as a static front page uses page and not paged
// https://codex.wordpress.org/Function_Reference/WP_Query#Pagination_Parameters
// $custom_query_args['paged'] = get_query_var( 'page' ) ? get_query_var( 'page' ) : 1;
@shizhua
shizhua / clean_wp_head.php
Last active September 29, 2016 22:22
Clean Up wp_head
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'start_post_rel_link');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'adjacent_posts_rel_link');
remove_action( 'wp_head', 'wp_shortlink_wp_head' );
@shizhua
shizhua / remove_wp_emoji.php
Created March 31, 2016 06:12
Remove WordPress Emoji Scripts and Styles
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('admin_print_styles', 'print_emoji_styles');
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action('embed_head', 'print_emoji_detection_script');
remove_filter('the_content_feed', 'wp_staticize_emoji');
remove_filter('comment_text_rss', 'wp_staticize_emoji');
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
@shizhua
shizhua / get_wp_editor_input.js
Last active September 29, 2016 23:57
Get the input content of TinyMCE editor
function get_tinymce_content(){
if (jQuery("#wp-editor_id-wrap").hasClass("tmce-active")){
return tinyMCE.activeEditor.getContent();
}else{
return jQuery('#html_text_area_id').val();
}
}