Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




wp_get_shortlink [ WordPress Function ]

wp_get_shortlink ( $id = 0, $context = 'post', $allow_slugs = true )
Parameters:
  • (int) $id A post or blog id. Default is 0, which means the current post or blog.
  • (string) $context Whether the id is a 'blog' id, 'post' id, or 'media' id. If 'post', the post_type of the post is consulted. If 'query', the current query is consulted to determine the id and context. Default is 'post'.
  • (bool) $allow_slugs Whether to allow post slugs in the shortlink. It is up to the plugin how and whether to honor this.
Returns:
  • (string) A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks are not enabled.
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ý

Dahasý ...

Kullanýcý Tartýþmalarý [ wordpress.org ]

- Bulunamadý -

Yeni bir konu yaz ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics