Created
November 5, 2012 22:35
-
-
Save stephanieleary/4020851 to your computer and use it in GitHub Desktop.
Shortlink All the Things
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: Shortlink All the Things | |
Description: Enables shortlinks for all custom post types. | |
Author: Stephanie Leary | |
Version: 1.0 | |
Author URI: http://stephanieleary.com | |
*/ | |
function shortlink_all_post_types($id = 0, $context = 'post', $allow_slugs = true) { | |
global $wp_query; | |
$post_id = 0; | |
if ( 'query' == $context && is_singular() && !is_search() && !is_404() ) { | |
$post_id = $wp_query->get_queried_object_id(); | |
} elseif ( 'post' == $context ) { | |
$post = get_post($id); | |
$post_id = $post->ID; | |
} | |
$options = get_option('us2011_theme'); | |
$shortlink = ''; | |
$structure = get_option('permalink_structure'); | |
if (!empty($options['shortlink_url'])) | |
$domain = $options['shortlink_url']; | |
else | |
$domain = site_url(); | |
// Return p= link for all public post types. | |
if ( !empty($post_id) && !empty($structure) ) { | |
$post = get_post($post_id); | |
$post_type = get_post_type_object( $post->post_type ); | |
if ( $post_type->public ) { | |
$shortlink = esc_url(trailingslashit($domain).'?p='.$post->ID); | |
} | |
} | |
return apply_filters('get_shortlink', $shortlink, $id, $context, $allow_slugs); | |
} | |
add_filter( 'pre_get_shortlink', 'shortlink_all_post_types'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment