Skip to content

Instantly share code, notes, and snippets.

Created March 29, 2022 06:11
What would you like to do?
Add Post Author 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])
// Add Simple HTML DOM for PHP-based HTML/DOM Traversal
include 'include/simple_html_dom.php';
// Add Author info to Recent Post Widgets Extended output (add before date)
function add_author_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);
$author_id = get_post_field( 'post_author', $post_id );
$author_display_name = get_the_author_meta( 'display_name', $author_id );
$title_tag = $title_link->parent();
$post_element = $title_tag->parent();
foreach($post_element->find('.rpwe-time') as $time_element){
$time_element_html = $time_element->outertext;
$time_element->outertext = '<span class="rpwe-author">'.$author_display_name.'</span> '.$time_element_html;
$html_output = $html; // Convert back to string
return $html_output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment