Skip to content

Instantly share code, notes, and snippets.

View ataylorme's full-sized avatar

Andrew Taylor ataylorme

View GitHub Profile
@ataylorme
ataylorme / print-archive-page-content
Created April 26, 2013 12:57
Print archive page content outside WordPress loop
<?php echo apply_filters('the_content', get_page($wp_query->get_queried_object_id())->post_content); //print content of blog page outside the loop ?>
$text = '<span class="black">Lorem Ipsum</span>';
$output = preg_replace('#</?span[^>]*>#is', '', $text);
@ataylorme
ataylorme / Add post ID to dashboard
Created February 28, 2013 13:48
for a CPT change "manage_posts_columns" and "manage_posts_custom_column" to use custom post type name instead of "posts"
/* ===== START ADD POST ID TO ADMIN ===== */
function posts_columns_id($defaults){
$defaults['wps_post_id'] = __('ID');
return $defaults;
}// end posts_columns_id function
function posts_custom_id_columns($column_name, $id){
if($column_name === 'wps_post_id'){
echo $id;
}
}// end posts_custom_id_columns function
<?php
add_theme_support('menus');
/*
http://codex.wordpress.org/Function_Reference/register_nav_menus#Examples
*/
register_nav_menus( array(
'main-menu' => 'Main Menu' // registers the menu in the WordPress admin menu editor
) );
/* ========== 410 TERMINATED EMPLOYEE PAGES =========== */
function 410_status_header(){
$terminatedEmployees = array('employee-1','employee-2','employee-3','employee-4','employee-5','employee-6','employee-7','employee-8', 'employee-9', 'employee-10');
$currentURL = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$currentURL = rtrim(rawurldecode( $currentURL ), '/');
foreach( $terminatedEmployees as $terminatedEmployee ):
if( get_bloginfo('url') . '/' . $terminatedEmployee === $currentURL ):
status_header( 410 );
if( !locate_template( '410.php', true ) )
echo 'Sorry, the page you requested has been permanently removed.';
@ataylorme
ataylorme / jQuery Validate US Currency
Last active December 11, 2015 17:58
disallows 0, negative numbers, blank value. Commas two decimal places are optional
$.validator.addMethod("UScurrency", function (value) {
return value.match(/^\$?[^-]?[1-9]([0-9]+,?)*(\.([0-9]{1,2}))?$/) || value == "" || Number(value) > 0;
}, "Please enter a valid dollar amount");
form.validate({
});
$.validator.addClassRules({
currency: {
UScurrency: true
@ataylorme
ataylorme / jQuery simple image rotator
Created January 21, 2013 16:27
Simple Image rotator
function rotateImages(slides) {
//Hide all slides
slides.hide();
//Show first slide
slides.eq(0).show();
//Set current slide to 0
var current = 0;
//Set total slides
var total = slides.length;
//Subtract one to make up for zero index
@ataylorme
ataylorme / .htaccess regex disallow
Created January 18, 2013 16:55
Disallow with regex in .htaccess
Order Allow,Deny
allow from all
<FilesMatch "^.*\.log$">
Deny from all
</FilesMatch>
@ataylorme
ataylorme / jQuery Validate Phone Number
Last active October 14, 2020 13:32
Adds phone number validation to jQuery Validate plugin in the format "(123) 456-7890". If any of the 3 sections contain all zeros the expression will return false
jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
phone_number = phone_number.replace(/\s+/g, "");
return this.optional(element) || phone_number.length > 9 &&
phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Please enter a valid phone number");
$.validator.addMethod('SocialSecurity',
function (value) {
return validSSN(value) || value == "";
}, 'Please enter a valid SSN'
);
function validSSN(value) {
var regex = /^([0-6]\d{2}|7[0-6]\d|77[0-2])([ \-]?)(\d{2})\2(\d{4})$/;
if (!regex.test(value)) {
return false;