Skip to content

Instantly share code, notes, and snippets.

View mikeselander's full-sized avatar
:shipit:
Shipping

Mike Selander mikeselander

:shipit:
Shipping
View GitHub Profile
@mikeselander
mikeselander / gform_field_value_{your_field}
Created February 28, 2014 03:27
This is an example of the gform_field_value function
/**
* Pre-populates a company ID into a Gravity Forms field from a GET variable
*
* @since 0.1.0
*
*/
add_filter('gform_field_value_company_id', 'company_id_population');
function company_id_population(){
// if we have the proper company GET variable - set the return variable
@mikeselander
mikeselander / get_short_content.php
Last active December 21, 2015 17:08
A companion function to the_short_content to return without any wpautop or echoing
function otm_get_short_content($length = 200) {
$content = strip_shortcodes( strip_tags( get_the_content(), '<p><h2><h3><h4>' ) );
if ( strlen( $content ) > $length ){
return wpautop( substr( $content, 0, strpos( $content, ' ', $length ) ) . "..." );
} else {
return wpautop( $content );
}
@mikeselander
mikeselander / the_short_content.php
Last active December 19, 2015 17:39
Shortened get_the_content() with a passable character length variable. Defaults to 200 characters
function otm_short_content( $length = 200 ) {
$content = strip_shortcodes( strip_tags( get_the_content(), '<p><h2><h3><h4>' ) );
if ( strlen( $content ) > $length ){
echo wpautop( substr( $content, 0, strpos( $content, ' ', $length ) ) . "..." );
} else {
echo wpautop( $content );
}