Answer the question
In order to leave comments, you need to log in
Show page images in wordpress menu without plugin?
Good time! There is a menu consisting of pages. Images have been added to the pages. I want to display images of these pages in the menu without a plugin. I do all operations in function.php I get pictures like this:
function get_post_img () {
$locations = get_nav_menu_locations();
$items = wp_get_nav_menu_items( $locations['menu-main'] );
foreach ( $items as $key => $menu_item ) {
$post_url = $menu_item->url;
$post_id = url_to_postid($post_url);
$post_img = get_the_post_thumbnail($post_id);
return $result = ''. $post_img . '';
}
}
add_filter( 'wp_nav_menu_args', 'add_item_img' );
function add_item_img( $args='' ){
$args['link_before'] = get_post_img ();
return $args;
}
Answer the question
In order to leave comments, you need to log in
Look towards Walker.
For more customization of the menu, you need a walker
https://wp-kama.ru/function/walker
https://misha.blog/wordpress/nav-menu-walkers.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question