반응형
wp_nav_menu에서 '홈' 링크를 삭제하는 방법!
사용 시 링크 상단에 '홈' 링크가 표시되지 않도록 하려면 어떻게 해야 합니까?<?php wp_nav_menu( array('menu' => 'news', 'show_home' => false)); ?>
나는 노력했다.'show_home' => false
그리고.'show_home=0'
둘 다 안 먹혔어요
이것은 당신의 기능에 있을 것입니다.php
function page_menu_args( $args ) {
$args['show_home'] = FALSE;
return $args;
}
add_filter( 'wp_page_menu_args', 'page_menu_args' );
편집: 메뉴가 인쇄되는 위치에 이 항목을 추가하는 것을 잊지 마십시오.
wp_nav_menu( array('echo'=>true));
다음과 같은 것이 도움이 되었습니다.
_nav_menu( array( 'container_id' => 'topmenu', 'depth' => 0, 'menu_class' => 'sf-menu', 'theme_location' => 'topmenu' ) );
덧붙이자면
function page_menu_args( $args ) {
$args['show_home'] = FALSE;
return $args;
}
add_filter( 'wp_page_menu_args', 'page_menu_args' );
에서functions.php
파일.
기본 워드프레스 메뉴(wp_page_menu)에서 홈 링크를 제거하고 홈이 페이지(블로그 포스트가 아님)인 경우 다음과 같이 해결합니다.
기능하고 있습니다.php:
function getPageBySlugname($slugname) {
$args = array(
'post_type' => 'page',
'hierarchical' => 0,
'post_status' => 'publish'
);
$pages = get_pages($args);
foreach ($pages as $page) {
if ($page->post_name == $slugname) {
return $page->ID;
}
}
}
인헤더php
wp_page_menu(array(
'container' => 'div',
'show_home' => false, // Not sure what this is hiding, maybe if you have blogposts as home??
'echo' => true,
'exclude' => getPageBySlugname('homepage-slugname'), // change this to your slugname
));
너무 어렵게 만들고 있어!대신 커스텀 메뉴의 특정 .home 항목에 대해 CSS display: none을 사용합니다.그것은 마법처럼 작용한다.예:
menu-blogroll .home {display:none !important;}
똑같은 걸 고치려고 jquery를 썼어요.
$("div.menu > ul li:first-child").css("display","none");
언급URL : https://stackoverflow.com/questions/5492495/how-to-remove-home-link-from-wp-nav-menu
반응형
'programing' 카테고리의 다른 글
추가 클래스가 jQuery의 함수가 아닙니다. (0) | 2023.03.26 |
---|---|
JSON 개체를 localStorage 어레이에 푸시 (0) | 2023.03.26 |
반응 컴포넌트 외부에 있는 레덕스 스토어에 액세스하는 가장 좋은 방법은 무엇입니까? (0) | 2023.03.26 |
한 페이지 앱에서 잘못된 URL(404 오류)에 대처하는 올바른 방법은 무엇입니까? (0) | 2023.03.26 |
같은 방법을 여러 번 연속으로 사용 (0) | 2023.03.21 |