Filter: wp_most_popular_list_item_single

This filter is used to filter the individual html element of the outputted widget list item. It can for example be used to change the output from a list item (li) to a div.

Filter Parameters

  • $html (string) – The HTML of the list item of the widget list
  • $post_id (int) – The ID of the post to be displayed
  • $title (string) – The title of the post to be displayed
  • $class (string) – The class of the HTML element of the post to be displayed
  • $permalink (string) – The permalink of the post to be displayed

Example

Changing the widget output from a list item (li) to a div.

<?php
/**
 * Replace the WP Most Popular widget's `li` element with a `div`.
 *
 * @param string $html The existing opening `li`.
 * @param int    $post_id The ID of the post.
 * @param string $title The post title.
 * @param string $class The class of the `li`.
 * @param string $permalink The link of the post.
 * @return string
 */
function thenga_change_wp_most_popular_list_item( $html, $post_id, $title, $class, $permalink ) {
   $html = '
<div><a href="' . esc_url( $permalink ) . '">' . esc_html( $title ) . '</a></div>

';
   return $html;
}
add_filter( 'wp_most_popular_list_item_single', 'thenga_change_wp_most_popular_list_item', 10, 5 );

Source

Found in system/widget.php

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.