Skip to content

Instantly share code, notes, and snippets.

@chrisguitarguy
Created September 3, 2011 22:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisguitarguy/1191865 to your computer and use it in GitHub Desktop.
Save chrisguitarguy/1191865 to your computer and use it in GitHub Desktop.
Adds a custom rewrite endpoint to WordPress for displaying galleries in the place of content.
<?php
/*
Plugin Name: Gallery Rewrite (for wpse27638)
Plugin URI: http://pmg.co
Description: Builds cutom rewrites to display a gallery or not.
Version: 1
Author: Christopher Davis
Author URI: http://pmg.co/people/chris
License: creative commons/GPL2
*/
register_activation_hook( __FILE__, 'wpse27638_activation' );
function wpse27638_activation()
{
wpse27638_add_rewrite();
flush_rewrite_rules();
}
register_deactivation_hook( __FILE__, 'wpse27638_deactivation' );
function wpse27638_deactivation()
{
flush_rewrite_rules();
}
add_action( 'init', 'wpse27638_add_rewrite' );
function wpse27638_add_rewrite()
{
add_rewrite_endpoint( 'gallery', EP_PERMALINK );
}
add_filter( 'request', 'wpse27638_request' );
function wpse27638_request( $vars )
{
if( isset( $vars['gallery'] ) ) $vars['gallery'] = true;
return $vars;
}
add_filter( 'the_content', 'wpse27638_content_filter' );
function wpse27638_content_filter( $content )
{
if( ! is_singular() ) return $content;
if( get_query_var( 'gallery' ) )
{
return '[gallery link="file"]';
}
else
{
return $content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment