Skip to content

Instantly share code, notes, and snippets.

@ramseyp
ramseyp / gist:1560867
Created January 4, 2012 16:41
Truncate WordPress post title
<?php
/**
* Truncate WordPress post title
* @author Pat Ramsey
* @link
*
* @param $title, $limit
*/
function s25_trunc_title( $limit ) {
@ramseyp
ramseyp / gist:1588929
Created January 10, 2012 12:53
List & remove WordPress roles left behind by plugins
<?php
$wp_roles = new WP_Roles();
$names = $wp_roles->get_names();
print_r($names);
$wp_roles->remove_role('name_of_role_to_be_removed');
?>
@ramseyp
ramseyp / text-grow-shrink.html
Created January 11, 2012 05:12
resize text based off container size
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Dynamic text sizing</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- From @Beejamin - http://stackoverflow.com/users/79068/beejamin -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
@ramseyp
ramseyp / short_user_descr.php
Created January 12, 2012 17:31
shorten user descriptions - WordPress
<?php
// filter user description to return something shorter
add_filter ( 'pre_user_description', 's25_short_description' );
function s25_short_description($description) {
$max_characters = 50;
if ( strlen( $description ) > $max_characters ) {
$description = substr( $description, 0, $max_characters + 1 );
$description = trim( substr( $description, 0, strrpos( $description, ' ' ) ) );
}
@ramseyp
ramseyp / gform_unixdatetime.php
Created January 17, 2012 20:31
convert gravity form date and time inputs to unix datetime
<?php
/*
* Takes a gravity form's date field & converts it to unix date/time format by populating a hidden field
*
*/
add_action('gform_pre_submission','s25_format_combstartdate');
function s25_format_combstartdate($form){
//submission form uid is 1
if($form["id"] != 1)
@ramseyp
ramseyp / jwplayer_metabox.php
Created January 19, 2012 21:21
How do display JWPlayer shortcode from custom meta box
<?php
/*
* The JW Player plugin drops shortcode into the editor. It's not filtered through WordPress's do_shortcode().
* You need to use jwplayer_tag_callback().
*/
global $post;
if (get_post_meta($post->ID, '_cmb_mini_wysiwyg', true) ):
$myvid = get_post_meta($post->ID, '_cmb_mini_wysiwyg', true);
$myvid = jwplayer_tag_callback( $myvid );
echo $myvid;
@ramseyp
ramseyp / list-child-pages-only.php
Created January 26, 2012 19:02
WordPress - list only direct children pages, not all levels of child pages
<?php
/* List only child pages of a page - not grandchildren
*/
?>
<ul class="clearfix">
<?php wp_list_pages( array('title_li'=>'','include'=>get_post_top_ancestor_id()) ); ?>
<?php wp_list_pages( array('title_li'=>'','depth'=>1,'child_of'=>get_post_top_ancestor_id()) ); ?>
</ul>
@ramseyp
ramseyp / sharing_caring.php
Created January 31, 2012 19:08
Social Media Sharing code for WordPress articles
<?php
/* Add a social media share box to your WordPress site.
If you want the email sharing, you'll need to install WP-Email: http://wordpress.org/extend/plugins/wp-email/
Insert <?php s25_sharing_caring(); ?> to your template where you want the box to appear. Must be used inside the Loop.
Facebook Like Button code can be built here: http://developers.facebook.com/docs/reference/plugins/like/
Tweet Button code: https://dev.twitter.com/docs/tweet-button
LinkedIn Share Button: http://developer.linkedin.com/plugins/share-plugin-generator
Google Plus 1: http://www.google.com/webmasters/+1/button/
@ramseyp
ramseyp / myscript.js
Created February 16, 2012 18:56
Sample jquery script for prepending an image to a link
jQuery(document).ready(function($){
$('a.fancybox').prepend('<img class="play" src="http://yoursite.com/path/to/img.png" alt="Play Video!" />');
});
@ramseyp
ramseyp / user-directory-page.php
Created February 23, 2012 17:09
WordPress User Directory - untested
<?php
/*
Template Name: User Directory
Inspirations for the code: @clarklab - http://clarklab.com/posts/sort-wordpress-users-by-custom-meta-value-with-get_users/
@scribu - http://scribu.net/wordpress/advanced-metadata-queries.html
*/
remove_action('genesis_loop', 'genesis_do_loop');