0

The current unmodified output looks like this →

<div id="archives-4" class="widget widget_archive">
    <h2 class="h2b">Archives</h2>       
    <ul>
        <li><a href="http://........./2017/11/">November 2017</a>&nbsp;(3)</li>
        <li><a href="http://........./2017/10/">October 2017</a>&nbsp;(9)</li>
        <li><a href="http://........./2017/09/">September 2017</a>&nbsp;(6)</li>
        <li><a href="http://........./2017/05/">May 2017</a>&nbsp;(7)</li>
        <li><a href="http://........./2017/04/">April 2017</a>&nbsp;(1)</li>
        <li><a href="http://........./2017/03/">March 2017</a>&nbsp;(5)</li>
        <li><a href="http://........./2017/02/">February 2017</a>&nbsp;(8)</li>
        <li><a href="http://........./2017/01/">January 2017</a>&nbsp;(1)</li>
    </ul>
</div>

But I want that finally, it should look like this →

<div id="archives-4" class="widget widget_archive newinjected_class1">
    <h2 class="h2b">Archives</h2>       
    <ul class="newinjected_class2">
        <li><a href="http://........./2017/11/">November 2017</a>&nbsp;(3)</li>
        <li><a href="http://........./2017/10/">October 2017</a>&nbsp;(9)</li>
        <li><a href="http://........./2017/09/">September 2017</a>&nbsp;(6)</li>
        <li><a href="http://........./2017/05/">May 2017</a>&nbsp;(7)</li>
        <li><a href="http://........./2017/04/">April 2017</a>&nbsp;(1)</li>
        <li><a href="http://........./2017/03/">March 2017</a>&nbsp;(5)</li>
        <li><a href="http://........./2017/02/">February 2017</a>&nbsp;(8)</li>
        <li><a href="http://........./2017/01/">January 2017</a>&nbsp;(1)</li>
    </ul>
</div>

Did you realize the new two classes:

newinjected_class1
newinjected_class2

Is this possible we can achieve this through some filter so that only output is modified without altering the normal behavior of the widget?

0

No, there are no filters for doing this. You would need to create your own version of the widgets in order to achieve this.

You can find the default WordPress widgets in the following folder: /wp-includes/widgets in your WordPress installation.

Simply copy the code from within the respective widget .php files in to your theme or plugin:

class-wp-widget-archives.php

and

class-wp-widget-categories.php

Then just edit the widget code to your liking.

Finally, you'll need to register the widgets using the register_widget() function as per the WordPress Codex page - https://codex.wordpress.org/Function_Reference/register_widget. Which should look something like this:

function myplugin_register_widgets() {
    register_widget( 'CustomArchiveWidget' );
    register_widget( 'CustomCategoriesWidget' );
}

add_action( 'widgets_init', 'myplugin_register_widgets' );
  • It is possible. – The WP Intermediate Apr 15 '18 at 0:05
  • Cool. Enlighten me... With jQuery/JS? – Mat Apr 15 '18 at 0:30
  • I dont know, but its possible. – The WP Intermediate Apr 15 '18 at 0:38
  • Ok... If you say so... I'd suggest you take a look at the default widget code. – Mat Apr 15 '18 at 0:39
  • 1
    That solution didn't filter what you want to filter and my answer is the only way to change what you want to change – Mat Apr 15 '18 at 23:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.