Created
September 3, 2011 22:16
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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