Skip to content

Instantly share code, notes, and snippets.

@KZeni
Created March 29, 2022 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KZeni/d1c0b5e95b08d51935da6d5d71961e27 to your computer and use it in GitHub Desktop.
Save KZeni/d1c0b5e95b08d51935da6d5d71961e27 to your computer and use it in GitHub Desktop.
Add Time to Recent Post Widgets Extended (RPWE) WordPress plugin output (uses Simple HTML DOM PHP [1.9.1 here] to aid in the HTML traversing & insertion])
<?php
// Add Simple HTML DOM for PHP-based HTML/DOM Traversal
if(!function_exists('str_get_html')){
include 'include/simple_html_dom.php';
}
// Add Time info to Recent Post Widgets Extended output (add after date)
function add_time_to_rpwe_markup($html,$args){
$html = str_get_html($html);
foreach($html->find('.rpwe-title a') as $title_link){
$permalink = $title_link->href;
$post_id = url_to_postid($permalink);
$time = get_the_date( 'g:i A', $post_id );
$title_tag = $title_link->parent();
$post_element = $title_tag->parent();
foreach($post_element->find('.rpwe-time') as $time_element){
$time_element_innerhtml = $time_element->innertext;
$time_element->innertext = $time_element_innerhtml.' '.$time;
}
}
$html_output = $html; // Convert back to string
return $html_output;
}
add_filter('rpwe_markup','add_time_to_rpwe_markup',10,2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment