Skip to content

Instantly share code, notes, and snippets.

@epierpont
epierpont / JS-toggle-form-field.js
Created March 27, 2015 18:04
JS - Toggle Form Field
//form toggle function
jQuery.fn.ToggleInputValue = function (){
return jQuery( this ).each(function (){
var Input = jQuery( this );
var default_value = Input.val();
Input.focus(function () {
if( Input.val() == default_value ) Input.val( '' );
}).blur(function(){
if( Input.val().length == 0 ) Input.val( default_value );
@epierpont
epierpont / WP-basic-widget.php
Last active August 29, 2015 14:18
WP - Basic Widget
<?php
add_action( 'widgets_init', 'load_custom_widgets' );
/* register widgets */
function load_custom_widgets() {
register_widget( 'basic_widget' );
}
/* add basic widget */
@epierpont
epierpont / WP-submenu-only.php
Created April 2, 2015 22:54
WP - Get specific submenu only
<?php
/* custom function for getting sub-menu only */
add_filter( 'wp_nav_menu_objects', 'submenu_limit', 10, 2 );
function submenu_limit( $items, $args ) {
if ( empty( $args->submenu ) ) {
return $items;
}
@epierpont
epierpont / CSS-secondary-jquery-nav.css
Created April 3, 2015 21:28
JS - Secondary jQuery nav
.secondary-nav {
display: none;
}
.secondary-nav.active {
display: block;
}
@epierpont
epierpont / PHP-truncate-string.php
Created April 6, 2015 22:10
PHP - Truncate string and add ellipsis
<?php
// shorten up string if need be
function truncate_string($string, $desired_width) {
$small_string = strlen($string) > $desired_width ? substr( $string, 0, $desired_width ) . "..." : $string;
return $small_string;
}
@epierpont
epierpont / WP-replace-excerpt-ellipsis.php
Last active August 29, 2015 14:18
WP- Replace excerpt ellipsis
<?php
// replace excerpt ellipsis with read more
add_filter('excerpt_more', 'excerpt_read_more');
function excerpt_read_more( $text ) {
return '... <a href="'. get_permalink($post->ID) . '">' . 'Read More &raquo;' . '</a>';
}
@epierpont
epierpont / WP-get-featured-image-url.php
Created April 7, 2015 22:47
WP - Get featured image URL
@epierpont
epierpont / HTACCESS-temp-resource-bump
Last active August 29, 2015 14:20
HTACCESS - Temp Resource Bump
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 259200
php_value max_input_time 259200
php_value memory_limit 256M
@epierpont
epierpont / WP-pages-to-posts.php
Last active August 29, 2015 14:20
WP - Move pages to posts and more
<?php
// this is a very specific script that moves pages to posts and assigns a category based on the parent. it also out outputs text for 301 redirects
$baseYear = 82; // 1998
$monthArr = array('1' => 'Jan/Feb', '2' => 'March/April', '3' => 'May/June', '4' => 'July/August', '5' => 'September/October', '6' => 'November/December');
$redirectStr = '';
global $wpdb;
$pages = $wpdb->get_results(
"
@epierpont
epierpont / WP-cpt-and-custom-tax.php
Created May 8, 2015 21:19
WP - Custom post type and category taxonomy
<?php
// set up custom post types
add_action( 'init', 'add_cpt' );
function add_cpt() {
$faq_labels = array(
'name' => 'FAQ',
'singular_name' => 'FAQ',