Skip to content

Instantly share code, notes, and snippets.

View scottlyttle's full-sized avatar

Scott Lyttle scottlyttle

View GitHub Profile
@scottlyttle
scottlyttle / comments.php
Last active December 12, 2015 02:48
Custom comments layout for a WordPress theme
// Place this in the comments.php theme file
<ol class="commentlist">
<?php wp_list_comments('type=comment&callback=frankiewp_comment'); ?>
</ol>
// Place this in functions.php
function frankiewp_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>">
@scottlyttle
scottlyttle / functions.php
Last active December 12, 2015 02:48
Basic implementation to register a new sidebar in WordPress (place in functions.php)
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => __('Sidebar Widgets','themename' ),
'id' => 'sidebar-widgets',
'description' => __( 'These are widgets for the sidebar.','themename' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
@scottlyttle
scottlyttle / .htaccess
Last active December 12, 2015 02:48
Basic .htaccess file for WordPress root
# Prevent directory browsing
Options All -Indexes
# Deny access to wp-config
<Files wp-config.php>
order allow,deny
deny from all
</Files>
# Deny access to htacess
@scottlyttle
scottlyttle / functions.php
Last active December 12, 2015 02:48
Basic implementation of registering scripts and styles in WordPress through functions.php
function themename_scripts() {
wp_enqueue_script('functions', get_template_directory_uri() . '/js/functions.js', array('jquery'));
wp_enqueue_style('custom-style', get_template_directory_uri() . '/css/custom-style.css');
}
add_action( 'wp_enqueue_scripts', 'themename_scripts' );
@scottlyttle
scottlyttle / password.sql
Created February 4, 2013 04:03
Update an WordPress users password through the database
UPDATE 'wp_users' SET 'user_pass' = MD5('NEWPASSWORD') WHERE 'user_login' ='username' LIMIT 1;
@scottlyttle
scottlyttle / imagefilter.php
Created February 5, 2013 00:39
Remove the width and height attributes from an inserted image in WordPress
add_filter( 'get_image_tag', 'remove_width_and_height_attribute', 10 );
add_filter( 'post_thumbnail_html', 'remove_width_and_height_attribute', 10 );
add_filter( 'image_send_to_editor', 'remove_width_and_height_attribute', 10 );
function remove_width_and_height_attribute( $html ) {
return preg_replace( '/(height|width)="\d*"\s/', "", $html );
}
@scottlyttle
scottlyttle / next-prev-overide.js
Last active December 14, 2015 10:49
jQuery snippet to output a span in place of a next or previous link in WordPress (as one is not output when there is no next previous page).
// store the links parent selectors as variables
var $next = $(".next");
var $prev = $(".prev");
// if the prev posts link doesn't exist but the next link does
if ($prev.children().length == 0 && $next.children().length > 0) {
// add a span with prev
$prev.append('<span class="disabled">Prev</span>');
// if the next posts link doesn't exist but the prev one does
} else if ($next.children().length == 0 && $prev.children().length > 0) {
// add a span with next
@scottlyttle
scottlyttle / functions.php
Created May 17, 2013 03:53
Wrap WordPress inserted images in <figure> and <figcaption> elements
function html5_insert_image($html, $id, $caption, $title, $align, $url) {
$html5 = "<figure id='post-$id media-$id' class='align-$align'>";
$html5 .= "<img src='$url' alt='$title' />";
if ($caption) {
$html5 .= "<figcaption>$caption</figcaption>";
}
$html5 .= "</figure>";
return $html5;
}
add_filter( 'image_send_to_editor', 'html5_insert_image', 10, 9 );
function g8_aus_address( $address_types, $form_id ){
$address_types["australia"] = array(
"label" => "Australian",
"country" => "Australia",
"zip_label" => "Postcode",
"state_label" => "State",
"states" => array(
"NT" => "NT",
"ACT" => "ACT",
"NSW" => "NSW",
@scottlyttle
scottlyttle / twitter.js
Created June 19, 2013 01:07
Custom client-side Twitter feed - from http://jasonmayes.com/projects/twitterApi/
/*********************************************************************
* #### Twitter Post Fetcher v7.0 ####
* Coded by Jason Mayes 2013. A present to all the developers out there.
* www.jasonmayes.com
* Please keep this disclaimer with my code if you use it. Thanks. :-)
* Got feedback or questions, ask here:
* http://www.jasonmayes.com/projects/twitterApi/
* Updates will be posted to this site.
*********************************************************************/
var twitterFetcher=function(){function t(d){return d.replace(/<b[^>]*>(.*?)<\/b>/gi,function(c,d){return d}).replace(/class=".*?"|data-query-source=".*?"|dir=".*?"|rel=".*?"/gi,"")}function m(d,c){for(var f=[],e=RegExp("(^| )"+c+"( |$)"),g=d.getElementsByTagName("*"),b=0,a=g.length;b<a;b++)e.test(g[b].className)&&f.push(g[b]);return f}var u="",j=20,n=!0,h=[],p=!1,k=!0,l=!0,q=null,r=!0;return{fetch:function(d,c,f,e,g,b,a){void 0===f&&(f=20);void 0===e&&(n=!0);void 0===g&&(g=!0);void 0===b&&(b=!0);