stevenselcuk
2/26/2019 - 1:45 PM

WordPress Filters & Some Functions etc.

WordPress Filters & Some Functions etc.

	/**
	 * 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');