Skip to content

Instantly share code, notes, and snippets.

View coffeepostal's full-sized avatar

Adam Farnsworth coffeepostal

View GitHub Profile
@coffeepostal
coffeepostal / wordpress.excerpt.length.php
Last active January 19, 2017 23:57
WordPress: Change the Excerpt Length
<?php
function wpdocs_custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 );
?>
@coffeepostal
coffeepostal / wordpress.list.all.categories.comma.separated.php
Created January 19, 2017 23:56
WordPress: List All Categories, Comma Separated
<?php
$categories = get_categories( array(
'orderby' => 'name',
'parent' => 0
) );
$category_list = array();
foreach ( $categories as $category ) {
$category_list[] = '<a href="' . get_category_link( $category->term_id ) . '">' . esc_html( $category->name ) . '</a> ';
}
@coffeepostal
coffeepostal / wordpress.custom.login.logo.php
Created February 6, 2017 20:38
WordPress: Custom Login Logo
// Change Login Logo
function my_login_logo() { ?>
<style type="text/css">
#login h1 a, .login h1 a {
background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/assets/images/site-login-logo.svg);
padding-bottom: 2rem;
background-size: 10rem 5rem;
background-position: center top;
background-repeat: no-repeat;
color: #999;
@coffeepostal
coffeepostal / jQuery.jshint.reset.js
Created February 8, 2017 01:42
jQuery: Tell CodeKit to ignore console.log, unused events and "== vs. ===" errors
/*jshint devel:true */
/*jslint eqeq: true*/
/*jshint unused:false*/
@coffeepostal
coffeepostal / jQuery.addCommasToThousands.js
Created February 17, 2017 23:19
jQuery: Add Commas to Thousands
function commaSeparateNumber(val){
while (/(\d+)(\d{3})/.test(val.toString())){
val = val.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2');
}
return val;
}
$('#inputID').val(commaSeparateNumber(1234567890));
@coffeepostal
coffeepostal / jquery.twoDecimalsWhenDecimalsArePresent.js
Created February 17, 2017 23:21
jQuery: Limit Decimals to Two Places Only When Decimals are Present
if(Math.round(val) !== val) {
val = val.toFixed(2);
}
@coffeepostal
coffeepostal / wordpress.add.acf.content.to.search.results.php
Last active March 21, 2017 19:34
WordPress: Add ACF Content to Search Results
/*******************************
ADD ACF TO SEARCH RESULTS
*******************************/
/* Join posts and postmeta tables: http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join */
function cf_search_join( $join ) {
global $wpdb;
if ( is_search() ) {
$join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
@coffeepostal
coffeepostal / wordpress.force.download.php
Last active March 1, 2017 00:52
WordPress: Force Download
<!-- PUT IN download.php: -->
<?php
/*
* This code delivers a file, specified in the URL parameter, as a forced "Save As" download.
*/
// First, get WordPress loaded
require_once('../../../wp-load.php'); // Modify this if necessary
@coffeepostal
coffeepostal / wordpress-get-blog-posts-page-url.php
Created March 8, 2017 20:50 — forked from kellenmace/get-blog-posts-page-url.php
WordPress: Get Blog Posts Page URL in WordPress
<?php
/**
* Get blog posts page URL.
*
* @return string The blog posts page URL.
*/
function km_get_blog_posts_page_url() {
// If front page is set to display a static page, get the URL of the posts page.
@coffeepostal
coffeepostal / wordpress-remove-archives-text-from-archive-title.php
Last active March 30, 2017 17:31
WordPress: Remove "Archives" from archive.php Title
<?php
// Remove "Archives" from archive.php title
add_filter( 'get_the_archive_title', function ( $title ) {
if( is_category() ): // Swap out conditional for custom post types, etc.
$title = single_cat_title( '', false );
endif;
return $title;