wp_get_shortlink [ WordPress Function ]
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Return a shortlink for a post, page, attachment, or blog.
This function exists to provide a shortlink tag that all themes and plugins can target. A plugin must hook in to provide the actual shortlinks. Default shortlink support is limited to providing ?p= style links for posts. Plugins can short-circuit this function via the pre_get_shortlink filter or filter the output via the get_shortlink filter.
Source
<?php
function wp_get_shortlink($id = 0, $context = 'post', $allow_slugs = true) {
// Allow plugins to short-circuit this function.
$shortlink = apply_filters('pre_get_shortlink', false, $id, $context, $allow_slugs);
if ( false !== $shortlink )
return $shortlink;
global $wp_query;
$post_id = 0;
if ( 'query' == $context && is_single() ) {
$post_id = $wp_query->get_queried_object_id();
} elseif ( 'post' == $context ) {
$post = get_post($id);
$post_id = $post->ID;
}
$shortlink = '';
// Return p= link for posts.
if ( !empty($post_id) && '' != get_option('permalink_structure') ) {
$post = get_post($post_id);
if ( isset($post->post_type) && 'post' == $post->post_type )
$shortlink = home_url('?p=' . $post->ID);
}
return apply_filters('get_shortlink', $shortlink, $id, $context, $allow_slugs);
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- Function Reference/wp get shortlink « WordPress Codex
Description. Returns the Short Link to a post for use in PHP. It does NOT display the short link. Usage. <?php wp_get_shortlink(); ?> Parameters. $id: (integer) ...
codex.wordpress.org - #14760 (wp_get_shortlink not working on pages) – WordPress Trac
wp_get_shortlink doesn't return anything on pages. reason: 2196 if ( isset($post- >post_type) && 'post' == $post->post_type ) 2197 $shortlink = home_url('?p=' .
core.trac.wordpress.org - wp_get_shortlink » Otto on WordPress
<div><span class="post-shortlink">Shortlink: <input type='text' value='<?php echo wp_get_shortlink(get_the_ID()); ?>' onclick='this.focus(); this.select();' ...
ottopress.com - wp_get_shortlink (WordPress Function) - WPSeek.com
Mar 16, 2010 ... WordPress lookup for wp_get_shortlink, a WordPress Function. wpseek.com is a WordPress-centric search tool for developers and theme ...
wpseek.com