Skip to content

Instantly share code, notes, and snippets.

@ramseyp
ramseyp / no_update_theme.php
Created November 14, 2013 15:26
Useful code if you don't want your WordPress them to show an update notice.
<?php
/**
* Keep your theme from updating
* http://markjaquith.wordpress.com/2009/12/14/excluding-your-plugin-or-theme-from-update-checks/
*/
function s25_no_update_theme( $r, $url ) {
if ( 0 !== strpos( $url, 'http://api.wordpress.org/themes/update-check' ) )
return $r; // Not a theme update request. Bail immediately.
$themes = unserialize( $r['body']['themes'] );
unset( $themes[ get_option( 'template' ) ] );
@ramseyp
ramseyp / hide_editor.php
Created October 28, 2013 20:30
Hide the WordPress editor on specific pages. This example looks for a page's name or a page template. The code goes in your functions.php file.
<?php
// Hide Editor on Select Pages
function s25_hide_editor() {
// Get the Post ID.
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
if( !isset( $post_id ) ) return;
// Hide the editor on the page titled 'Homepage'
$homepgname = get_the_title($post_id);
@ramseyp
ramseyp / cmb_page_id.php
Last active December 21, 2015 01:28
If you use this custom meta box code: https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress then this gist may be useful. It allows you to use the page slug as a "show-on" filter.
<?php
/**
* Use the page slug to filter the 'show-on' of a meta box
* @author Pat Ramsey
* @link https://gist.github.com/ramseyp/6227383
*
* @param bool $display
* @param array $meta_box
* @return bool display metabox
*/
@ramseyp
ramseyp / wp_show_custom_meta.php
Last active December 20, 2015 20:59
Returns first value of WordPress custom field. Runs it though wpautop() if desired. Has option for you to insert text / html before and after the value, allowing you to wrap the value with content.
<?php
/**
* Displays the content of a custom field, along with wrapping code or content.
* @param string $key name, or key, of the custom field.
* @param string $before what should be shown directly before the custom field value.
* @param string $after what is output directly after the custom field value.
* @param boolean $wpautop filters the value through wpautop().
* @return string first value of the custom field, prepended by $before, followed by $after.
*/
@ramseyp
ramseyp / show_testimonials.php
Last active December 17, 2015 09:19
Grab a custom post type of testimonial & output it, along with a custom field for the person's credentials / title
<?php
$testimeta = get_post_custom($testimq->post->ID);
if ( $testimeta['s25_testim_cred'][0] !='' ) { $cred = ', '. $testimeta['s25_testim_cred'][0]; } else { $cred = ''; }
echo '<div class="entry-content">'. wpautop( get_the_content($testimq->post->ID), true ) .'</div>';
echo '<p class="attrib"><em>&ndash; '. get_the_title($testimq->post->ID) . $cred .'</em></p>';
echo '</div>';
}
@ramseyp
ramseyp / full-screen-bg.php
Created May 12, 2013 14:25
function for outputting a full-screen background image based off a custom field of "s25_bg_image"
<?php
function s25_full_bg() {
$pgmeta = get_post_custom();
$pgbg = $pgmeta['s25_bg_image'][0];
if ( !is_null( $pgbg ) ) :
echo '<style type="text/css">body{background-image:none !important;background-color:#000 !important;}</style>';
echo '<div class="lpage_bg" style="position:fixed;left:0;top:0;width:100%;height:100%;z-index:-1;background: #ccc url('. $pgbg .') no-repeat fixed center center;-webkit-background-size: cover;-moz-background-size: cover;-o-background-size: cover;background-size: cover;filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'. $pgbg .'", sizingMethod=\'scale\');-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'. $pgbg .'", sizingMethod=\'scale\')";>&nbsp;</div>';
echo '<!--[if IE 8 ]>
$(function() {
var $sidebar = $("#sidebar"),
$window = $(window),
offset = $sidebar.offset(),
topPadding = 20;
$window.scroll(function() {
if ($window.scrollTop() > offset.top) {
$sidebar.stop().animate({
<?php
function namespace_add_custom_types( $query ) {
if( is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array( 'post', 'case_study','solution_sheet','white_paper' );
$query->set( 'post_type', $post_type );
return $query;
@ramseyp
ramseyp / short-titles.php
Created February 28, 2013 18:34
Shorten WordPress titles to a set number of characters
<?php
/**
* [short_title description]
* @param $postid the ID of the $post object
* @param $length How long the title should be
* @return Post / Page title shortened to the number of characters in $length
* Usage: short_title( $postid, 45 );
*/
function short_title( $postid,$length) {
global $post;
@ramseyp
ramseyp / genesis-child-webfonts.php
Created January 17, 2013 05:58
Load Google Webfonts into a Genesis Child Theme using the functions.php file
/**
*
* Add Google Webfonts
*/
add_action('wp_head','s25_webfont_load');
function s25_webfont_load() {
echo '<link href="//fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic,700italic|Archivo+Black" rel="stylesheet" type="text/css" />';
}