Skip to content

Instantly share code, notes, and snippets.

@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();
}
}
@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');
<?php
add_filter( 'manage_posts_columns', 'ws_cutom_columns_head', 20 );
add_action( 'manage_posts_custom_column', 'ws_cutom_columns_content', 10, 2 );
function ws_cutom_columns_head( $columns ) {
$columns['ws_post_id'] = 'ID';
return $columns;
@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 / image-sizes.php
Last active June 15, 2016 19:25
List all image sizes in a WordPress post
<?php
/**
* List all image sizes in a WordPress post
* by Leo
* URL: http://wpsites.org/?p=10617
*/
$images = array();
$image_sizes = get_intermediate_image_sizes();
array_unshift( $image_sizes, 'full' );
$img_id = get_post_thumbnail_id( get_the_ID() );
@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 / 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 / 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;