Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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