Created
February 26, 2019 13:45
-
-
Save stevenselcuk/9aa4a9f4a5588c89337c39458a11d616 to your computer and use it in GitHub Desktop.
WordPress Filters & Some Functions etc.
This file contains 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
/** | |
* Displays posts date modifing with human time. | |
* | |
* It looks like ( 22 hours ago ) or ( 7 years ago ) | |
* | |
* @method yourprefix_get_humantime() | |
* | |
* @link https://codex.wordpress.org/Function_Reference/human_time_diff | |
* | |
* @uses human_time_diff() | |
* | |
* @since 1.0.0 | |
*/ | |
function yourprefix_add_humantime( $content ) { | |
if( is_single() ) { | |
$beforecontent = '<time class="post-date humantime" datetime="' . esc_attr( get_the_date( 'c' ) ) . '">' . esc_html( human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) ) . ' ago</time>'; | |
$aftercontent = ''; | |
$fullcontent = $beforecontent . $content . $aftercontent; | |
} else { | |
$fullcontent = $content; | |
} | |
return $fullcontent; | |
} | |
add_filter('the_content', 'yourprefix_add_humantime'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment