Skip to content

Instantly share code, notes, and snippets.

View scottlyttle's full-sized avatar

Scott Lyttle scottlyttle

View GitHub Profile
@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 / 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 / .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 / 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 / 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 / header.php
Last active September 17, 2016 19:19
Clean up the WordPress header output (put it in functions.php)
function removeHeadLinks() {
remove_action( 'wp_head', 'feed_links_extra', 3 ); // Display the links to the extra feeds such as category feeds
remove_action( 'wp_head', 'feed_links', 2 ); // Display the links to the general feeds: Post and Comment Feed
remove_action( 'wp_head', 'rsd_link' ); // Display the link to the Really Simple Discovery service endpoint, EditURI link
remove_action( 'wp_head', 'wlwmanifest_link' ); // Display the link to the Windows Live Writer manifest file.
remove_action( 'wp_head', 'index_rel_link' ); // index link
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // prev link
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // start link
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 ); // Display relational links for the posts adjacent to the current post.
remove_action( 'wp_head', 'wp_generator' ); // Display the XHTML generator that is generated on the wp_head hook, WP version