WordPress.org

Ready to get started?Download WordPress

Forums

Custom Menu Images
[Plugin: Custom menu images] Put generated styles inside the head tag (3 posts)

  1. sayaka
    Member
    Posted 3 years ago #

    Hi, I've changed some functions of this great plugin.

    these are my changes:

    function get_custom_menu_image_css($menuItems, $args){
    		$custom_options = (get_option($this->prefix));
    		foreach ($menuItems as $key => $val ) {
    			$menuItems[$key]->classes = array('menu_item_'.$val->ID);
    			$image_url = ($custom_options[$val->ID]['url_type'] != 'lib' ? $custom_options[$val->ID]['url'] : $custom_options[$val->ID]['media_lib']);
    			if($image_url != '') {
                                $this->styles[] = 'li.menu-item.menu_item_'.$val->ID.' a{ background-image: url('.$image_url.'); } ';
                            }
    		}
    
                    if($this->styles[0] != '<style>')
                        array_unshift($this->styles, '<style>');
                    else
                        if(end($this->styles) != '</style>')
                            $this->styles[] = '</style>';
    
    		return $menuItems;
    	}
    function print_custom_menu_image_css(){
        $new_styles = "";
        foreach ($this->styles as $line){
            $new_styles .= $line;
        }
        ?>
        <script type="text/javascript">
        //<!--
            jQuery(document).ready(function(){
                jQuery("head").append("<?php echo $new_styles; ?>");
            });
        //-->
        </script>;
        <?php
    }
  2. sayaka
    Member
    Posted 3 years ago #

    I forgot say that, my adaptation is based on changes made by thirdboxcar.

  3. anabelle
    Member
    Plugin Author

    Posted 3 years ago #

    Thanks for sharing back :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic