Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@BronsonQuick
BronsonQuick / basic_testimonials_custom_post_type.php
Created March 4, 2012 06:34
A basic Testimonials Custom Post Type for WordPress
<?php add_action( 'init', 'sennza_register_cpt_testimonial' );
function sennza_register_cpt_testimonial() {
$args = array(
'public' => true,
'query_var' => 'testimonial',
'rewrite' => array(
'slug' => 'testimonials',
'with_front' => false
),
@BronsonQuick
BronsonQuick / meta_boxes_for_testimonials_cpt.php
Created March 4, 2012 06:40
Add meta boxes to the Testimonials WordPress CPT
<?php /**
* Adds a custom meta box to the Testimonials editor page for collecting
* Testimonial meta.
* Refer to: https://gist.github.com/1971046 for the Custom Post Type Setup
*
* @since 1.0
*/
function sennza_add_meta_boxes() {
add_meta_box( 'sennza_testimonials_meta_box', __( 'Testimonial Details' ), 'sennza_testimonials_meta_box', 'testimonial', 'side', 'core' );
}
@BronsonQuick
BronsonQuick / random_testimonial_widget.php
Created March 4, 2012 06:46
A WordPress widget to generate random Testimonials from the Testimonials Custom Post Type
<?php if( ! class_exists( 'Testimonials_Widget' ) ) :
/**
* Create a widget to display a random testimonial post.
* Refer to https://gist.github.com/1971046 and https://gist.github.com/1971054 for the Custom Post Type and Meta Box Setup
*
* @since 1.0
*/
class Testimonials_Widget extends WP_Widget {
function Testimonials_Widget() {
@BronsonQuick
BronsonQuick / loop_through_post_attachments.php
Created March 4, 2012 06:56
A WordPress loop to display post/page attachments
<?php /*
* This is just a simple loop to display 7 attachments attached to a post or page in WordPress
* You can change 'medium' and 'thumbnail' to add sizes you have definied in your theme by the add_image_size function
* in WordPress
*/
?>
<div id="thumbs" class="pic_list">
<ul class="thumbs">
<?php /* Time to create a new loop that pulls out the first 7 image attachments for this post */
$args = array( 'post_type' => 'attachment', 'numberposts' => 7, 'post_status' => null, 'post_parent' => $post->ID );
@BronsonQuick
BronsonQuick / add_anchor_to_tinymce.php
Created March 4, 2012 07:03
Add the anchor button back to the TinyMCE editor in WordPress
<?php /*
* Add the anchor link button back to the TinyMCE Editor in WordPress
*/
function sennza_mce_buttons( $buttons ){
array_push( $buttons, "anchor" );
return $buttons;
}
add_filter( 'mce_buttons', 'sennza_mce_buttons' ); ?>
@BronsonQuick
BronsonQuick / add_categories_to_pages.php
Created March 4, 2012 07:06
Add Categories to Pages in WordPress
<?php /*
* In some weird occasions Pages need to have Categories like Posts in WordPress.
*/
add_action( 'init', 'sennza_add_page_cats' );
function sennza_add_page_cats()
{
register_taxonomy_for_object_type( 'category', 'page' );
}
?>
@BronsonQuick
BronsonQuick / add_superscript_to_tinymce.php
Created March 4, 2012 07:15
Add back the Superscript button in the TinyMCE editor in WordPress
<?php
/* Add back the superscript TinyMCE button in WordPress */
function sennza_add_more_buttons( $buttons )
{
$buttons[] = 'sup';
return $buttons;
}
add_filter( 'mce_buttons_3', 'sennza_add_more_buttons' );
?>
@BronsonQuick
BronsonQuick / enhanced_excerpt.php
Created March 4, 2012 07:24
Extract the_content in WordPress but only bring back links and <strong> tags
<?php /*
* Sometimes you will might want something like the_excerpt but still want <strong> tags. Add this function and call it
* inside your theme template file e.g. sennza_enhanced_excerpt();
*/
function sennza_enhanced_excerpt( $content ) {
$content = strip_shortcodes( $content );
$content = str_replace( ']]>', ']]&gt;', $content );
$content = preg_replace( '/<img[^>]+./','',$content );
$content = preg_replace( '%<div.+?</div>%is', '', $content );
$content = preg_replace( '%<object.+?</object>%is', '', $content );
@BronsonQuick
BronsonQuick / cromwell-downloads-widget.php
Created March 4, 2012 07:34
A WordPress widget to display all attachments to a post/page of a certain type
<?php
/*
* A WordPress widget that displays all PDF's attached to the current post
* You can adapt this widget to extract other file types by altering the 'post_mime_type' => 'application/pdf'
* argument refer to: http://en.wikipedia.org/wiki/Internet_media_type#List_of_common_media_types for mime types
*/
class Sennza_PDF_Download_Widget extends WP_Widget
{
/** constructor */
@BronsonQuick
BronsonQuick / add_hr_to_tinymce.php
Created March 4, 2012 07:40
Add the horizontal rule <hr> button back to the TinyMCE editor in WordPress
<?php /*
* Add the horizontal rule button back to the WordPress TinyMCE editor
*/
function sennza_hr_button($buttons) {
$buttons[] = 'hr';
return $buttons;
}
add_filter( 'mce_buttons', 'sennza_hr_button' ); ?>