• Resolved Yourit

    (@yourit)


    Hi,

    I’m currently trying to add a Bootstrap class to the <select> of the archives widget into the functions.php file, so the select dropdown is styled correctly when checked in the CMS, but somehow i’m not able to find out what i’m doing wrong.

    This is how it looks like right now(HTML):
    <select name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">

    This is how it should look like(HTML):
    <select class="form-control" name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">

    I’ve tried a str_replace in functions.php but it won’t affect wp_get_archives.

    Could someone please help me find a solution?
    Thanks in advance!!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Dion

    (@diondesigns)

    An inelegant-but-effective solution would be to remove the default Archives widget and replace it with a copy of your own that has the replacement HTML built in. Something like this:

    class New_Widget_Archives extends WP_Widget {
    	(your version of widget)
    }
    
    function fix_archives_widget() {
    	unregister_widget('WP_Widget_Archives');
    	register_widget('New_Widget_Archives');
    }
    
    add_action('widgets_init', 'fix_archives_widget');

    Thread Starter Yourit

    (@yourit)

    Thanks DionDesigns!
    I’m not sure if this is the right solution for my project, but I might use it.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘add class to archives widget in functions.php’ is closed to new replies.