Skip to content

Instantly share code, notes, and snippets.

@epierpont
epierpont / WP-json-cache.php
Last active August 29, 2015 14:16
WP - Get remote json file and cache
<?php
// using http://codex.wordpress.org/Function_Reference/wp_remote_get and http://codex.wordpress.org/Transients_API
// if transient has expired then recreate, if not grab from db
if ( false === ( $featured_trans = get_transient( 'featured_trans' ) ) ) {
$featured_args = array(
'timeout' => 5,
'redirection' => 5,
@epierpont
epierpont / WPF-author-excerpt.php
Last active August 29, 2015 14:16
WP Function - Get author bio excerpt
<?php
function author_excerpt() {
$word_limit = 45;
$txt_end = '...';
$author_desc = explode( ' ', get_the_author_meta( 'description' ) );
$author_desc_short = array_slice( $author_desc, 0, ( $word_limit ) );
return ( implode( $author_desc_short, ' ' ) ) . $txt_end;
@epierpont
epierpont / JS-jquery-email-validate.js
Last active August 29, 2015 14:16
JS - Simple jQuery email validation
// validate email address from form, good for email newsletter signup
$( 'form input.submit' ).click(function() {
var email_address = $( 'form input.email' ).val();
if ( /(.+)@(.+){2,}\.(.+){2,}/.test( email_address ) ) {
return true;
} else {
alert( 'Invalid Email Address' );
return false;
}
@epierpont
epierpont / WP-enqueue-scripts.php
Last active August 29, 2015 14:16
WP - Enqueue scripts
<?php
// using http://codex.wordpress.org/Function_Reference/wp_enqueue_script
// basic enqueue script
add_action( 'wp_enqueue_scripts', 'load_scripts' );
function load_scripts() {
wp_register_script( 'functions-js', get_stylesheet_directory_uri() . '/_/js/functions.js', array(), '', true );
@epierpont
epierpont / JS-jquery-broken-image.js
Last active August 29, 2015 14:16
JS - jQuery hide broken image based on filename
// hide broken images
$( '.post img' ).each(function () {
var img = $(this);
var src = img.attr( 'src' ).split( '/' );
var file = src[src.length - 1];
if( file == "x.gif" ) {
img.hide();
}
@epierpont
epierpont / CSS-responsive-video.css
Created March 9, 2015 16:46
WP - Wrap class around videos
.video-container {
width: 100%;
position: relative;
padding-bottom: 56.25%; /* 16:9 */
padding-top: 25px;
height: 0;
}
.video-container iframe {
position: absolute;
top: 0;
@epierpont
epierpont / CSS-responsive-grid.css
Last active August 29, 2015 14:17
CSS - Basic responsive grid setup
/* this is based off of http://cobyism.com/gridism/ */
/* responsive grid setup - going mobile first here
-------------------------------------------------------------------------------*/
.grid {
display: block;
clear: both;
}
@epierpont
epierpont / GIT.gitignore
Last active August 29, 2015 14:17 — forked from octocat/.gitignore
GIT - Ignore file
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@epierpont
epierpont / WP-search-form.css
Created March 19, 2015 15:27
WP - Search form with font awesome
nav form .search-field {
border: 0;
}
nav form .search-submit {
font-family: 'FontAwesome';
border: 0;
}
@epierpont
epierpont / PHP-database-connect-test.php
Last active August 29, 2015 14:17
PHP - Test MySQL database connection
<?php
$conn = mysql_connect( "host", "user", "pass" );
if ( !$conn ) {
echo "Unable to connect to server.";
} else {
$db = mysql_select_db( "database", $conn );
if ( !$db ) {
echo "Unable to select database.";