Skip to content

Instantly share code, notes, and snippets.

@psflannery
psflannery / thumb_background.php
Created June 23, 2013 18:35
Sets the thumbnail image as background to a div
<header class="entry-header row" <?php
if ( $thumbnail_id = get_post_thumbnail_id() ) {
if ( $image_src = wp_get_attachment_image_src( $thumbnail_id, 'x-large-size' ) )
printf( ' style="background-image: url(%s);"', $image_src[0] );
}
?>>
@psflannery
psflannery / clickable_parent_div
Created June 18, 2013 15:27
Here’s an easy way to make the parent div of a link clickable. Let’s say you have this html code - http://css-tricks.com/snippets/jquery/make-entire-div-clickable/
/**
<div class="myBox">
blah blah blah.
<a href="http://google.com">link</a>
</div>
*/
$(".myBox").click(function(){
window.location=$(this).find("a").attr("href");
return false;
@psflannery
psflannery / image_preloader
Created June 18, 2013 15:25
Ever noticed how fast images load when paging through a Facebook photo album? This is because Facebook is preloading each of these images into your browser’s cache before you even view them. Here’s how you can achieve a similar behavior on your website using some jQuery magic. - http://www.nealgrosskopf.com/tech/thread.php?pid=77
var nextimage = "/images/some-image.jpg";
$(document).ready(function(){
window.setTimeout(function(){
var img = $("<img>").attr("src", nextimage).load(function(){
//all done
});
}, 100);
});
@psflannery
psflannery / auto_twitter_link.php
Last active December 18, 2015 02:39
Once you saved the file all twitter usernames in posts and comments will automatically be linked to their Twitter profiles. Usernames have to be written under the form @username. @link: http://www.wpbeginner.com/wp-tutorials/how-to-automatically-link-twitter-usernames-in-wordpress/
<?php $recent = new WP_Query("page_id=**ID**"); while($recent->have_posts()) : $recent->the_post();?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php endwhile; ?>
@psflannery
psflannery / image sizes in WP uploader
Created May 12, 2013 13:47
Add new image sizes to the media upload/insert interface.
// http://pippinsplugins.com/add-custom-image-sizes-to-media-uploader/
function pw_add_image_sizes() {
add_image_size( 'pw-thumb', 300, 100, true );
add_image_size( 'pw-large', 600, 300, true );
}
add_action( 'init', 'pw_add_image_sizes' );
function pw_show_image_sizes($sizes) {
$sizes['pw-thumb'] = __( 'Custom Thumb', 'pippin' );
@psflannery
psflannery / Add class to every third post
Created May 10, 2013 16:15
Adds a class to every nth post -- Wordpress
<?php if (have_posts()) : ?>
<?php $c = 0;while (have_posts()) : the_post(); $c++;
if( $c == 3) {
$style = 'third';
$c = 0;
}
else $style='';
// this goes in the loop
?>