Skip to content

Instantly share code, notes, and snippets.

@shizhua
shizhua / js.js
Created Jun 8, 2016
SVG circular progress
View js.js
$('#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 Jun 4, 2016
Add unlimited sidebar in WordPress
View custom-sidebar.css
.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
"update notice" for self-hosted themes
View update-notice.php
<?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 Jul 16, 2021
Multiple checkbox customizer control
View custom-control.js
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 Apr 27, 2016 — forked from AllThingsSmitty/script-loaded.js
Check if any given script has loaded
View script-loaded.js
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 Apr 27, 2017
Frontend Image Uploader in WordPress
View ajax.js
( 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 Apr 12, 2016
Fix pagination not working in custom query
View pagination_custom_query.php
<?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 Sep 29, 2016
Clean Up wp_head
View clean_wp_head.php
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 Mar 31, 2016
Remove WordPress Emoji Scripts and Styles
View remove_wp_emoji.php
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 Sep 29, 2016
Get the input content of TinyMCE editor
View get_wp_editor_input.js
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();
}
}