Skip to content

Instantly share code, notes, and snippets.

@leanda
leanda / gist:5014169
Created February 22, 2013 15:23
WordPress: Remove caption width and add figcaption (use in functions.php)
/*--- Remove inline caption width for responsive themes ---*/
add_filter('img_caption_shortcode', 'my_img_caption_shortcode_filter',10,3);
function my_img_caption_shortcode_filter($val, $attr, $content = null)
{
extract(shortcode_atts(array(
'id' => '',
'align' => 'aligncenter',
'width' => '',
@leanda
leanda / footer.php
Last active January 17, 2017 16:55
WordPress: Custom footer menus with titles
@leanda
leanda / date-year.php
Created March 12, 2013 16:33
PHP: Date
<?php echo date("Y"); ?>
@leanda
leanda / wp-page-template
Created March 21, 2013 14:26
WordPress: Page Template
<?php
/*
Template Name: Template Name
*/
?>
@leanda
leanda / list-custom-taxonomy.php
Created March 29, 2013 12:21
WordPress: List custom taxonomy
<ul>
<?php
// list product categories
$orderby = 'name';
$show_count = 0;
$pad_counts = 0;
$hierarchical = 1;
$taxonomy = 'brands';
$title = '';
@leanda
leanda / category-slug-class.php
Created April 3, 2013 08:51
WordPress: Output for the post's categories, building on get_the_category() adds category slug as a class.
<?php $sep = '';
foreach((get_the_category()) as $cat) {
echo $sep . '<a href="' . get_category_link($cat->term_id) . '" class="cat-' . $cat->slug . '" title="View all posts in '. esc_attr($cat->name) . '">' . $cat->cat_name . '</a>';
$sep = ', ';
}
?>
@leanda
leanda / gist:5379767
Created April 13, 2013 19:45
WordPress: Conditional Meta Box
function create_meta_box() {
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
$template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
// check for a template type
if ($template_file == 'homepage.php') {
// add_meta_box( $id, $title, $callback, $post_type, $context, $priority, $callback_args );
add_meta_box( 'new_meta_box', 'Home Page Blockquote', 'new_meta_box', 'page', 'side', 'low' );
@leanda
leanda / text-area-meta.php
Last active December 16, 2015 04:49
WordPress: Conditional Text Area Meta Box
// custom meta box
add_action( 'admin_menu', 'create_meta_box' );
add_action( 'save_post', 'save_meta_box' );
function create_meta_box() {
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
$template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
// check for a template type
if ($template_file == 'homepage.php') {
@leanda
leanda / gzip
Created June 22, 2013 15:41
gzip compression
# Gzip compression allows us to drastically reduce out file sizes. This .htaccess snippet does the gzipping for us..
<IfModule mod_deflate.c>
# html, xml, css, and js:
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript text/javascript application/javascript application/json
# webfonts and svg:
<FilesMatch "\.(ttf|otf|eot|svg)$" >
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
@leanda
leanda / antispam.php
Created August 19, 2013 17:49
WP: Email Anti Spam
<a href="mailto:<?php echo antispambot('[email protected]' ) ?>"><?php echo antispambot('[email protected]') ?></a>