Skip to content

Instantly share code, notes, and snippets.

@kaseybon
kaseybon / mullet-loop.php
Last active September 20, 2019 16:42
Wordpress Mullet Loop: Place this loop in the index.php. Gives the option to pull in a custom content template for the most recent blog post in the blog feed e.g. Show full blog post for most recent post while only showing excerpts for older posts.
<?php if (have_posts()) : ?>
<?php $count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?>
<!-- Check for the first blog post in the loop && makes sure it the first page of results && makes sure it is the blog -->
<?php if ($count == 1 && $paged == 0 && is_home()) : ?>
<!-- Most recent blog post with custom template will display above older entries - Requires a content-featured.php or whatever you want to name your file or replace with code -->
<?php get_template_part( 'content', 'featured' ); ?>
@kaseybon
kaseybon / sibling-pagination.php
Last active December 30, 2015 01:38
Adds WordPress pagination to child, sibling pages. Will not add pagination to parent pages. Must be used with the Next Page, Not Next Post plugin: http://wordpress.org/plugins/next-page-not-next-post/
<?php //Add to page.php ?>
<?php if($post->post_parent !== 0) {
$nextPage = next_page_not_post();
$prevPage = previous_page_not_post();
if (!empty($nextPage) || !empty($prevPage)) {
if (!empty($prevPage)) echo '<span class="previous-sibling">'.$prevPage.'</span>';
if (!empty($nextPage)) echo '<span class="next-sibling">'.$nextPage.'</span>';
}
} ?>
@kaseybon
kaseybon / img-loading.js
Created December 4, 2013 21:18
jQuery - Run a function after all images in a certain element have loaded. When calculating heights the function usually runs before the images have loaded giving inaccurate calculations. This will fun the function again each time an image loads.
$('.container-class').find('img').load(function() {
functionToRun();
});
@kaseybon
kaseybon / horizontal-rule.php
Created December 10, 2013 20:07
Adds a <hr /> button to the WordPress editor.
function enable_more_buttons($buttons) {
$buttons[] = 'hr';
return $buttons;
}
add_filter("mce_buttons", "enable_more_buttons");
@kaseybon
kaseybon / clean-menu-classes.php
Created December 13, 2013 19:29
WordPress function to remove unnecessary classes from menu items.
<?php
function cleanname($v) {
$v = preg_replace('/[^a-zA-Z0-9s]/', '', $v);
$v = str_replace(' ', '-', $v);
$v = strtolower($v);
return $v;
}
// Reduce nav classes, leaving only 'current-menu-item'
function nav_class_filter( $var ) {
return is_array($var) ? array_intersect($var, array('current-menu-item')) : '';
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kaseybon
kaseybon / only-new.php
Created January 24, 2014 19:48
Only displays WordPress posts from the last 30 days. Also works with custom post types.
<?php
function filter_where($where = '') {
//posts in the last 30 days
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
return $where;
}
add_filter('posts_where', 'filter_where');
query_posts($query_string);
?>
@baseFont: 16;
@outer: 50;
@margin: 20;
// Mixins
.inner-box() {
@inner: @outer - @margin;
@innerRem: @inner / @baseFont;
@MarginRem: @margin / @baseFont;
border-radius: ~"@{inner}px";
@kaseybon
kaseybon / smooth-scroll.js
Created April 1, 2014 15:39
jQuery Smooth Scroll - for anchors on the same page.
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
@kaseybon
kaseybon / remove-related-products.php
Created May 28, 2014 13:17
Removes the related products section from WooCommerce. Add to functions.php