Skip to content

Instantly share code, notes, and snippets.

View georgiecel's full-sized avatar
😜
I mean I do nothing on GitHub

Georgie Luhur Cooke georgiecel

😜
I mean I do nothing on GitHub
View GitHub Profile
@georgiecel
georgiecel / html-in-category-desc
Created June 24, 2015 13:37
allow HTML in category descriptions in WordPress db – insert into functions.php
remove_filter( 'pre_term_description', 'wp_filter_kses' );
remove_filter( 'pre_link_description', 'wp_filter_kses' );
remove_filter( 'pre_link_notes', 'wp_filter_kses' );
remove_filter( 'term_description', 'wp_kses_data' );
@georgiecel
georgiecel / search_highlight
Created June 24, 2015 13:29
highlight the search term in the title & excerpt in WordPress – insert into functions.php; use <?php search_excerpt_highlight(n); ?> where n is excerpt word limit
function search_excerpt_highlight( $limit ) {
$excerpt = get_the_excerpt();
$excerpt = explode(' ', get_the_excerpt(), $limit);
if ( count( $excerpt ) >= $limit ) {
array_pop( $excerpt );
$excerpt = implode(' ', $excerpt);
} else {
$excerpt = implode(' ', $excerpt);
}
@georgiecel
georgiecel / nice_search
Created June 24, 2015 13:27
friendly URL for WordPress search (/search/term/) – insert into functions.php
@georgiecel
georgiecel / remove_self_closing_tags
Created June 24, 2015 13:21
remove self-closing tags in WordPress (unneeded if coding in HTML5) – insert into functions.php
function remove_self_closing_tags($input) {
return str_replace(' />', '>', $input);
}
add_filter('get_avatar', 'remove_self_closing_tags'); // <img />
add_filter('comment_id_fields', 'remove_self_closing_tags'); // <input />
add_filter('post_thumbnail_html', 'remove_self_closing_tags'); // <img />
@georgiecel
georgiecel / wordcount
Created June 24, 2015 13:18
word count for WordPress post, use <?php echo wordcount(); ?> in the post loop
function wordcount() {
ob_start();
the_content();
$postcontent = ob_get_clean();
return sizeof(explode(" ", $postcontent));
}
@georgiecel
georgiecel / caption_shortcode
Last active August 29, 2015 14:23
semantic figure and figcaption elements for captioned images in WordPress – insert into functions.php
function caption_shortcode($val, $attr, $content = null) {
extract(shortcode_atts(array('id'=> '','align'=> 'aligncenter','width'=> '','caption' => ''), $attr));
if ( 1 > (int) $width || empty($caption) )return $val;
$capid = '';
if ( $id ) {
$id = esc_attr($id);
$capid = 'id="figcaption_'. $id . '" ';
$id = 'id="' . $id . '" aria-labelledby="figcaption_' . $id . '" ';
@georgiecel
georgiecel / wp-comment-walker
Last active December 28, 2022 15:16
Custom comment walker for HTML5 friendly WordPress comment and threaded replies. To be inserted in functions.php.
<?php
class comment_walker extends Walker_Comment {
var $tree_type = 'comment';
var $db_fields = array( 'parent' => 'comment_parent', 'id' => 'comment_ID' );
// constructor – wrapper for the comments list
function __construct() { ?>
<section class="comments-list">
@georgiecel
georgiecel / wp-comment-callback
Created March 9, 2014 09:09
Custom callback for HTML5 friendly WordPress comment. Also includes schema.org microdata. To use, insert the following into comments.php: <?php wp_list_comments('callback=better_comment&end-callback=better_comment_close'); ?>
// awesome semantic comment
function better_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
extract($args, EXTR_SKIP);
if ( 'article' == $args['style'] ) {
$tag = 'article';
$add_below = 'comment';
} else {