Skip to content

Internal Shortcode | [Guid]

EkoJr edited this page Mar 16, 2017 · 3 revisions

Description

Adds the post/page unique url (aka Guid). WP's Default URL (.com/?p=396).

It is usually preferred to use [post_permalink] structure.

Usage

[post_guid]

Return

(string) WP_Post Guid.

Examples/Sample

Example 1

[guid]

Returns

http://example.com/?p=123

Source

File: advanced-post-list/includes/class/apl_shortcodes.php

/**
 * Post Guid (WP Default URL) Shortcode. 
 * 
 * Desc: Adds the post/page Guid. WP's Default URL (.com/?p=396).
 * 
 * 1. Add to return Post's Guid.  
 * 2. Return string. 
 * 
 * @since 0.1.0
 * @version 0.4.0 - Changed to Class function, and uses WP's built-in
 *                  functions for setting default attributes & do_shortcode().
 * 
 * @param array $atts {}.
 * @return string Post Guid.
 */
public function guid($atts)
{
    //INIT
    $atts_value = shortcode_atts( array() , $atts, 'post_guid');
    $return_str = '';
    
    //STEP 1
    $return_str .= $this->_post->guid;
    
    //STEP 2
    return $return_str;
}

Additional Resources

Related

[post_permalink] - WP Default URL.

Clone this wiki locally