Insert a image before/after the “nav” tag
-
I want to attach specific image to current menu item. For this purpose, I check whether an item has “current-menu-item” css class or not.
if( in_array( 'current-menu-item', $classes ) ):
And then I insert specific image
<img src="<?=get_post_meta($item->ID, '_om_aitm_attached_image', true);?>">
get_post_meta returns the URL of the image (The image exists in the wp media library)
But this image insert in the “nav” tag. I want to insert the image before/after the “nav” tag. How can I do it ?
This image shows my problem
https://i.piccy.info/i9/6a87fb6033215320965de9f87eedeaef/1506883479/254105/1131628/Untitled.jpgCode
filter
add_filter( 'nav_menu_css_class', array( $this, 'om_aitm_nav_menu_css_class'), 10, 2 );
Callback function
Problem: This image insert in the “nav” tag. I want to insert the image before/after the “nav” tag.function om_aitm_nav_menu_css_class( $classes, $item ) { if( in_array( 'current-menu-item', $classes ) ): ?> <img src="<?=get_post_meta($item->ID, '_om_aitm_attached_image', true);?>"> <?php endif; return $classes; }
The page I need help with: [log in to see the link]
- The topic ‘Insert a image before/after the “nav” tag’ is closed to new replies.