Skip to content

Instantly share code, notes, and snippets.

View ataylorme's full-sized avatar

Andrew Taylor ataylorme

View GitHub Profile
@ataylorme
ataylorme / php-divisible-by
Created November 15, 2012 08:07
Php divisible by
if(($count % $number) == 0){
//do something
}
@ataylorme
ataylorme / add-page-post-id-to-backend
Created November 15, 2012 08:24
Add page/post ID to backend
<?php
function posts_columns_id($defaults){
$defaults['wps_post_id'] = __('ID');
return $defaults;
}// end posts_columns_id function
function posts_custom_id_columns($column_name, $id){
if($column_name === 'wps_post_id'){
echo $id;
}
}// end posts_custom_id_columns function
@ataylorme
ataylorme / add-nofollow-comment-link
Created November 17, 2012 22:26
Add rel="nofollow" to comment reply links
@ataylorme
ataylorme / add-rel-prettyphoto-to-images-in-content
Created November 17, 2012 22:27
add rel="prettyPhoto" to images in the content
//start function to add rel attribute to image links
function rel_prettyPhoto($link) {
global $post;
$find ="/<a(.*?)href=('|")(.*?).(bmp|gif|jpeg|jpg|png)('|")(.*?)>/i";
$replace = '<a$1href=$2$3.$4$5 rel="prettyPhoto['. $post->ID .']" $6>';
$link = preg_replace($find, $replace, $link);
return $link;
} //end function to add rel attribute to image links
//add rel attribute function to the content filter
@ataylorme
ataylorme / add-sortable-custom-field-columns-to-wordpress-backend
Created November 17, 2012 22:30
Add sortable custom field columns to WordPress backend
// Register the column
function METAKEYHERE_column_register( $columns ) {
$columns['METAKEYHERE'] = __( 'COLUMNLABEL', 'POSTTYPE' );
return $columns;
}
add_filter( 'manage_edit-POSTTYPE_columns', 'METAKEYHERE_column_register' );
// Display the column content
function METAKEYHERE_column_display( $column_name, $post_id ) {
@ataylorme
ataylorme / change-custom-field-metakey-in-wordpress-database
Created November 17, 2012 22:34
Change custom field metakey in WordPress database
function ChangeMetaKey($old, $new){
global $wpdb;
$wpdb->query( "
update $wpdb->postmeta
set meta_key = '$new'
where meta_key = '$old'
");
}//end change metakey
@ataylorme
ataylorme / change-title-placeholder-of-custom-post-type
Created November 17, 2012 22:36
Change title placeholder of custom post type
function CUSTOMPOSTTYPE_change_default_title( $title ){
$screen = get_current_screen();
//only update the title if on CUSTOMPOSTTYPE
if ( 'CUSTOMPOSTTYPE' == $screen->post_type )
$title = 'NEW PLACEHOLDER HERE';
return $title;
}
add_filter( 'enter_title_here', 'CUSTOMPOSTTYPE_change_default_title' );
@ataylorme
ataylorme / wordpress-coupon-pop-up-shortcode
Created November 17, 2012 22:37
WordPress coupon pop-up shortcode
add_image_size( 'coupon-thumb', 250, 115, true );
function coupons_shortcode() {//start coupon shortcode function shortcode
global $COUPONS_name, $COUPONS_prefix, $post;
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID,
'post_mime_type' => 'image'
@ataylorme
ataylorme / curl-request-to-get-xml-from-rss-f
Created November 17, 2012 22:38
Curl request to get xml from rss feed
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'FEEDURL');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$feed = curl_exec($ch);
curl_close($ch);
@ataylorme
ataylorme / custom-menu-shortcode
Created November 17, 2012 22:40
Custom Menu Shortcode
// Function that will return Wordpress menu
function custom_menu($atts, $content = null) {
extract(shortcode_atts(array(
'menu' =&gt; '',
'container' =&gt; 'div',
'container_class' =&gt; '',
'container_id' =&gt; '',
'menu_class' =&gt; 'menu',
'menu_id' =&gt; '',
'echo' =&gt; true,