• sayaka

    (@sayaka)


    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
    }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Custom menu images] Put generated styles inside the head tag’ is closed to new replies.