Skip to content

Instantly share code, notes, and snippets.

View katmoody's full-sized avatar

Katrina Moody katmoody

View GitHub Profile
/* Creates random keys for confirm checkbox */
function generate_confirm_key($length = 50) {
$characters = '-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
@katmoody
katmoody / README.md
Last active August 29, 2015 14:10 — forked from icryptic/README.md

WordPress database clean up queries

Orphan rows

Since WordPress uses MyISAM for it's storage engine, we don't get foreign keys - thus orphan rows can show themselves.

wp_posts -> wp_posts (parent/child)

SELECT * FROM wp_posts
LEFT JOIN wp_posts child ON (wp_posts.post_parent = child.ID)

Contract Killer

The popular open-source contract for web designers and developers by Stuff & Nonsense

  • Originally published: 23/12/2008
  • Revised date: 15/12/2013
  • Original post

@katmoody
katmoody / Search Form in Specific WP Nav
Last active August 29, 2015 14:09
Adds search form to Specific Navigation with Theme Location - Replace "example.com" with your site's primary URL
add_filter('wp_nav_menu_items', 'add_search_form', 10, 2);
function add_search_form($items, $args) {
if( $args->theme_location == 'secondary' )
$items .= '<li class="search"><form method="get" class="search-form" action="http://example.com/" role="search"><input type="search" name="s" placeholder="Search..."><input type="submit" value="Search"></form></li>';
return $items;
}
// Add Read More Link to Excerpts
add_filter('excerpt_more', 'get_read_more_link');
add_filter( 'the_content_more_link', 'get_read_more_link' );
function get_read_more_link() {
return '...&nbsp;<a href="' . get_permalink() . '">[Read&nbsp;More]</a>';
}