Skip to content

Instantly share code, notes, and snippets.

@ramseyp
ramseyp / cat_archive_search.php
Created January 10, 2014 02:09
Search within a WordPress category archive ( Genesis )
<?php
/**
*
* first function gets URL of the current page, which is used in the search as the action parameter.
* second function loads a search box above the content of a Genesis category archive.
* the category name ( slug ) is passed through a hidden input as a search query parameter.
*
**/
function current_page_url() {
$pageURL = 'http';
@ramseyp
ramseyp / 0_reuse_code.js
Created December 19, 2013 18:45
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ramseyp
ramseyp / no_update_plugin.php
Created November 14, 2013 15:27
Simple code useful if you don't want a WordPress plugin to show an update notice.
<?php
/**
* Keep your plugin from updating
* http://markjaquith.wordpress.com/2009/12/14/excluding-your-plugin-or-theme-from-update-checks/
*/
function s25_plugin_no_update( $r, $url ) {
if ( 0 !== strpos( $url, 'http://api.wordpress.org/plugins/update-check' ) )
return $r; // Not a plugin update request. Bail immediately.
$plugins = unserialize( $r['body']['plugins'] );
unset( $plugins->plugins[ plugin_basename( __FILE__ ) ] );
@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 / filter_yoast_seo.php
Created October 10, 2013 15:11
Filter Yoast Meta Box Priority - returning low moves it below standard meta boxes
<?php
// Filter Yoast Meta Priority
function move_yoast_seo_box() {
if ( defined( 'WPSEO_VERSION' ) ) :
add_filter( 'wpseo_metabox_prio', function() { return 'low'; } );
endif;
}
add_action('admin_init', 'move_yoast_seo_box');
@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 / base-slider.php
Created July 17, 2013 00:17
Basic carousel / slider code using flexslider.
<?php
/**
* Basic slider. Uses flexslider.js, theme options framework, a custom post type and custom meta boxes.
*
* @author Pat Ramsey
* @link http://slash25.com
*/
add_image_size( 'slider', 920, 286, true ); // we want a new image size for the slider background
@ramseyp
ramseyp / lastname-firstname-user-sort.php
Created June 28, 2013 15:33
Sorted the return of a Wp_User_Query by both the last name value and the first name value. This way, if multiple users have the same last name, those particular users are then sorted by first name.
<?php
function s25_member_loop() {
$args = array(
'role' => 'member', // the role we're targeting
'exclude' => '1', // exclude admin
'fields' => 'all_with_meta',
'meta_key' => 'last_name', //query on the last_name key
'meta_key' => 'first_name', // also the first_name key
);
$membersquery = new WP_User_Query( $args );