Skip to content

Instantly share code, notes, and snippets.

<?php
function dimox_breadcrumbs() {
/* === OPTIONS === */
$text['home'] = 'Home'; // text for the 'Home' link
$text['category'] = 'Archive by Category "%s"'; // text for a category page
$text['search'] = 'Search Results for "%s" Query'; // text for a search results page
$text['tag'] = 'Posts Tagged "%s"'; // text for a tag page
$text['author'] = 'Articles Posted by %s'; // text for an author page
@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 / like-it-enqueue.php
Last active September 25, 2023 12:48
Add a like button without a plugin in WordPress
add_action( 'wp_enqueue_scripts', 'pt_like_it_scripts' );
function pt_like_it_scripts() {
if( is_single() ) {
wp_enqueue_style( 'like-it', trailingslashit( plugin_dir_url( __FILE__ ) ).'css/like-it.css' );
if (!wp_script_is( 'jquery', 'enqueued' )) {
wp_enqueue_script( 'jquery' );// Comment this line if you theme has already loaded jQuery
}
wp_enqueue_script( 'like-it', trailingslashit( plugin_dir_url( __FILE__ ) ).'js/like-it.js', array('jquery'), '1.0', true );
<?php
/**
* Function: Redirect to a random post
* URL: http://wpsites.org/?p=10370
* by Leo
*/
add_action('init','random_add_rewrite');
function random_add_rewrite() {
global $wp;
$wp->add_query_var('random');
<?php if( function_exists( 'pt_time_to_read' ) ) { echo pt_time_to_read( 'Time to read: ', ' Minutes' ); } ?>
@shizhua
shizhua / excerpt-character-count.php
Created August 24, 2015 13:53
Add a Character Counter to Excerpt box
<?php
/**
* Add a Character Counter to Excerpt box
* URL: http://wpsites.org/?p=10503
*/
function excerpt_count_js(){
echo '<script>jQuery(document).ready(function(){
jQuery("#postexcerpt .handlediv").after("<div style=\"position:absolute;top:5px;right:80px;color:#666;\"><small>Excerpt length: </small><input type=\"text\" value=\"0\" maxlength=\"3\" size=\"3\" id=\"excerpt_counter\" readonly=\"\" style=\"background:#fff;\"> <small>character(s). (128 Characters MAX)</small></div>");
jQuery("#excerpt_counter").val(jQuery("#excerpt").val().length);
@shizhua
shizhua / hide-admin-bar.php
Created August 24, 2015 13:54
Hide the admin bar in wordpress
<?php
add_filter( 'show_admin_bar', '__return_false' );
remove_action( 'wp_footer', 'wp_admin_bar_render', 1000 );
?>
@shizhua
shizhua / remove-comment-url.php
Created August 24, 2015 13:57
Remove URL field from comment form in wordpress
<?php
/**
* Remove URL field from comment form in wordpress
* by Leo
* URL: http://wpsites.org/?p=10448
*/
add_filter('comment_form_default_fields', 'website_remove_url');
function website_remove_url( $fields ) {
if ( isset($fields['url']) ) {
unset( $fields['url'] );