Skip to content

Instantly share code, notes, and snippets.

<?php
add_action( 'save_post', 'be_div_shortcode_filter', 10, 2 );
function be_div_shortcode_filter( $post_ID, $post ) {
// Make sure we're on the actual post, not a revision
if( wp_is_post_revision( $post ) )
return;
// Filter the content through the dean_is_awesome function that converts
@billerickson
billerickson / gist:1250866
Created September 29, 2011 14:40
Twenty Links - Redirect single posts
<?php
// in functions.php
// Find URL in post
function be_find_url( $content ) {
preg_match( '|href=["]([^\'^"]+)["]|mi', $content, $m );
return $m[1];
}
// Redirect single posts to linked URL
@billerickson
billerickson / gist:1267777
Created October 6, 2011 15:56
Improvements to Display Posts Shortcode
<?php
/**
* Plugin Name: Display Posts Shortcode
* Plugin URI: http://www.billerickson.net/shortcode-to-display-posts/
* Description: Display a listing of posts using the [display-posts] shortcode
* Version: 1.6
* Author: Bill Erickson
* Author URI: http://www.billerickson.net
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
@billerickson
billerickson / gist:1270278
Last active January 4, 2019 02:16
Customize outer markup of Display Posts Shortcode
<?php
/**
* Customize opening outer markup of Display Posts Shortcode
* @see https://displayposts.com/2019/01/04/use-section-element-for-wrapper/
*
* @param $output string, the original opening markup
* @return $output string, the modified opening markup
*/
function be_display_posts_open( $output, $atts, $query ) {
@billerickson
billerickson / gist:1273008
Created October 8, 2011 22:47
Example of Metabox
<?php
/**
* Create Metaboxes
*
* @link http://www.billerickson.net/wordpress-metaboxes/
* @param array
* @return array
*
*/
@billerickson
billerickson / genesis-190.diff
Created October 9, 2011 14:48
Patch to make genesis seo and layout options post-type-specific
Index: lib/admin/inpost-metaboxes.php
===================================================================
--- lib/admin/inpost-metaboxes.php (revision 227)
+++ lib/admin/inpost-metaboxes.php (working copy)
@@ -22,7 +22,7 @@
function genesis_add_inpost_seo_box() {
foreach ( (array)get_post_types( array( 'public' => true ) ) as $type ) {
- if ( post_type_supports( $type, 'genesis-seo' ) || $type == 'post' || $type = 'page' ) {
+ if ( post_type_supports( $type, 'genesis-seo' ) ) {
<item>
<title><?php the_title_rss() ?></title>
<link><?php the_permalink_rss() ?></link>
<comments><?php comments_link_feed(); ?></comments>
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
<dc:creator><?php the_author() ?></dc:creator>
<?php the_category_rss('rss2') ?>
<guid isPermaLink="false"><?php the_guid(); ?></guid>
<?php if (get_option('rss_use_excerpt')) : ?>
@billerickson
billerickson / gist:1279091
Created October 11, 2011 19:15
How to handle redirects in WordPress
Otto:
Step 1: Just try it as is and see what happens. WordPress's canonical
redirection is pretty darned clever in some ways, and it often can
guess the right thing to serve out of the box.
Step 2: If the built in canonical redirection isn't able to detect and
redirect accordingly, then you can add your own code to discover and
handle the redirections. The way you do this is with the
redirect_canonical filter.
@billerickson
billerickson / gist:1281517
Last active September 27, 2015 14:07
Add author to display posts shortcode
<?php
/**
* Add Author to Display Posts Shortcode plugin
* @author Bill Erickson
* @link http://wordpress.org/extend/plugins/display-posts-shortcode/
*
* @param $output string, the original markup for an individual post
* @param $atts array, all the attributes passed to the shortcode
* @param $image string, the image part of the output
* @param $title string, the title part of the output
@billerickson
billerickson / gist:1285290
Created October 13, 2011 19:40
rewrite endpoints
<?php
/**
* Blog Rewrite Endpoint
* Used for filtering blog posts. Ex: most comments
*
* @since 1.0
*/
function be_add_blog_rewrite_endpoint() {
add_rewrite_endpoint( 'filter', EP_ALL );