Skip to content

Internal Shortcode | [Post_Modified]

EkoJr edited this page Jan 3, 2017 · 3 revisions

Description

Adds the post/page modified date & time as server's timezone.

Usage

[post_modified format="m-d-Y"]

Params

format

(string) (optional) Format used via PHP.

Return

(string) WP_Post Post_Modified.

Examples/Sample

Example 1

[post_modified format="m-d-Y"]

Returns

9-27-2016

Source

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

/**
 * Post Date Modified Shortcode. 
 * 
 * Desc: Adds the post/page modified date.
 * 
 * 1. Get & Add to return Post's Formatted Modified Date.  
 * 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().
 * 
 * @link http://php.net/manual/en/function.date.php
 * 
 * @param array $atts {
 *      
 *      Shortcode Attributes.
 *      
 *      @type string $format Used to format date via PHP function.
 *      
 * }
 * @return string Post Modified.
 */
public function post_modified($atts)
{
    //INIT
    $atts_value = shortcode_atts( array(
        'format' => 'm-d-Y'
    ), $atts, 'post_date');
    $return_str = '';
    
    //STEP 1
    $return_str .= mysql2date($atts_value['format'], $this->_post->post_modified);
    
    //STEP 2
    return $return_str;
}

Additional Resources

Related

Clone this wiki locally