찾다
백엔드 개발PHP 튜토리얼WordPress development_php 스킬 중 wp_title() 함수 사용법에 대한 자세한 설명

워드프레스의 wp_title 함수는 기사 제목, 페이지, 카테고리 등을 표시하는 데 사용되는 함수이지만, 홈페이지 색인에서는 이 함수가 아무것도 표시하지 않습니다. 이 기능은 항상 공식 WordPress 테마에서 사용되었지만 많은 사용자 정의 테마에서는 항상 무시됩니다.

함수 의미에 대한 자세한 설명
wp_title 함수는 페이지 제목을 표시하는 데 사용됩니다. 예를 들어 기사 페이지에서는 기사 제목이 표시되고, 카테고리 이름은 홈페이지 색인에 표시됩니다. 아무것도 표시하지 않습니다.
이는 WordPress의 get_the_title 및 Single_cat_title() 두 함수를 적응적으로 사용하는 것과 약간 비슷합니다(페이지, 기사, 카테고리, 아카이브 또는 태그인지 자동으로 확인).

함수 선언
좀 긴 글이니 한 번이라도 인내심을 갖고 읽어주시길 바랍니다.

/**
 * Display or retrieve page title for all areas of blog.
 *
 * By default, the page title will display the separator before the page title,
 * so that the blog title will be before the page title. This is not good for
 * title display, since the blog title shows up on most tabs and not what is
 * important, which is the page that the user is looking at.
 *
 * There are also SEO benefits to having the blog title after or to the 'right'
 * or the page title. However, it is mostly common sense to have the blog title
 * to the right with most browsers supporting tabs. You can achieve this by
 * using the seplocation parameter and setting the value to 'right'. This change
 * was introduced around 2.5.0, in case backwards compatibility of themes is
 * important.
 *
 * @since 1.0.0
 *
 * @param string $sep Optional, default is '»'. How to separate the various items within the page title.
 * @param bool $display Optional, default is true. Whether to display or retrieve title.
 * @param string $seplocation Optional. Direction to display title, 'right'.
 * @return string|null String on retrieve, null when displaying.
 */
function wp_title($sep = '»', $display = true, $seplocation = '') {
global $wpdb, $wp_locale;
 
$m = get_query_var('m');
$year = get_query_var('year');
$monthnum = get_query_var('monthnum');
$day = get_query_var('day');
$search = get_query_var('s');
$title = '';
 
$t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
 
// If there is a post
if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
 $title = single_post_title( '', false );
}
 
// If there's a category or tag
if ( is_category() || is_tag() ) {
 $title = single_term_title( '', false );
}
 
// If there's a taxonomy
if ( is_tax() ) {
 $term = get_queried_object();
 $tax = get_taxonomy( $term->taxonomy );
 $title = single_term_title( $tax->labels->name . $t_sep, false );
}
 
// If there's an author
if ( is_author() ) {
 $author = get_queried_object();
 $title = $author->display_name;
}
 
// If there's a post type archive
if ( is_post_type_archive() )
 $title = post_type_archive_title( '', false );
 
// If there's a month
if ( is_archive() && !empty($m) ) {
 $my_year = substr($m, 0, 4);
 $my_month = $wp_locale->get_month(substr($m, 4, 2));
 $my_day = intval(substr($m, 6, 2));
 $title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
}
 
// If there's a year
if ( is_archive() && !empty($year) ) {
 $title = $year;
 if ( !empty($monthnum) )
 $title .= $t_sep . $wp_locale->get_month($monthnum);
 if ( !empty($day) )
 $title .= $t_sep . zeroise($day, 2);
}
 
// If it's a search
if ( is_search() ) {
 /* translators: 1: separator, 2: search phrase */
$title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search));
}
 
// If it's a 404 page
if ( is_404() ) {
 $title = __('Page not found');
}
 
$prefix = '';
if ( !empty($title) )
 $prefix = " $sep ";
 
// Determines position of the separator and direction of the breadcrumb
if ( 'right' == $seplocation ) { // sep on right, so reverse the order
$title_array = explode( $t_sep, $title );
$title_array = array_reverse( $title_array );
$title = implode( " $sep ", $title_array ) . $prefix;
} else {
 $title_array = explode( $t_sep, $title );
 $title = $prefix . implode( " $sep ", $title_array );
}
 
$title = apply_filters('wp_title', $title, $sep, $seplocation);
 
// Send it out
 if ( $display )
 echo $title;
 else
 return $title;
 
}

사용방법

<&#63;php wp_title( $sep, $echo, $seplocation ); &#63;>

매개변수 상세 설명

  • $sep: 구분 기호
  • $echo: 표시 여부
  • $seplocation : 구분 기호 위치(왼쪽 또는 오른쪽, '오른쪽'만 허용, 오른쪽이 아닌 경우 자동으로 왼쪽으로 판단)

요약

WordPress에는 동일한 기능을 가진 많은 기능이 있으며 기본 수준에서 고급 수준까지 캡슐화되어 최종적으로 사용 계층에 도달합니다. 물론 유연한 사용법이 필요한 경우에는 해당 기능을 직접 사용할 수 있습니다. 중간 레이어. 그렇다면 wp_title 함수와 같은 가장 고급 함수 레이어를 직접 사용할 수 있습니다. 실제로 wp는 다양한 유형의 페이지에서 이 함수를 수행합니다. 카테고리, 태그, 기사, 아카이브, 저자, 페이지 등과 같은 목적을 달성하기 위해 다양한 페이지에 따라 다양한 제목 기능을 판단하고 호출합니다.
시간이 되시면 다음 기능들에 대해 심도있게 공부하시고 SEO를 좀 더 유연하게 수행하실 수 있습니다
기사 페이지에서 제목을 추출하는 Single_post_title 함수
Single_term_title 태그(태그), cat(카테고리), 날짜, Single_cat_title() 함수와 유사한 제목 추출 함수
get_queried_object 작성자 페이지에서 개체를 추출하는 함수(개체에는 작성자 이름이 있음)
post_type_archive_title() 파일과 제목을 추출하는 기타 기능
당신은 무엇을 기다리고 있습니까?
GO GO GO!

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
PHP 코드 최적화 : 메모리 사용 및 실행 시간을 줄입니다PHP 코드 최적화 : 메모리 사용 및 실행 시간을 줄입니다May 10, 2025 am 12:04 AM

tooptimizephpcodeforregedmemoryUsageancutionEcution-time, followthesesteps : 1) usereferencesinsteAdArgedArgedArgeDatureStoredUcememoryConsumption.2) leveragephp'sbuilt-infunctionslikearray_mapforfosterexecution

PHP 이메일 : 단계별 보내기 안내서PHP 이메일 : 단계별 보내기 안내서May 09, 2025 am 12:14 AM

phpisusedforendingemailsduetoitsintegrationwithsermailservices 및 externalsmtpproviders, 1) setupyourphpenvironmentwitheberverandphp, temailfuncpp를 보장합니다

PHP를 통해 이메일을 보내는 방법 : 예 및 코드PHP를 통해 이메일을 보내는 방법 : 예 및 코드May 09, 2025 am 12:13 AM

이메일을 보내는 가장 좋은 방법은 Phpmailer 라이브러리를 사용하는 것입니다. 1) Mail () 함수를 사용하는 것은 간단하지만 신뢰할 수 없으므로 이메일이 스팸으로 입력되거나 배송 할 수 없습니다. 2) Phpmailer는 더 나은 제어 및 신뢰성을 제공하며 HTML 메일, 첨부 파일 및 SMTP 인증을 지원합니다. 3) SMTP 설정이 올바르게 구성되었는지 확인하고 (예 : STARTTLS 또는 SSL/TLS) 암호화가 보안을 향상시키는 데 사용됩니다. 4) 많은 양의 이메일의 경우 메일 대기열 시스템을 사용하여 성능을 최적화하십시오.

고급 PHP 이메일 : 사용자 정의 헤더 및 기능고급 PHP 이메일 : 사용자 정의 헤더 및 기능May 09, 2025 am 12:13 AM

CustomHeadersAndAdAncedFeaturesInpHeAmailEnhanceFectionality.1) 1) CustomHeadersAdDmetAdataFortrackingand Categorization.2) htmlemailsallowformattingandinteractivity.3) attachmentSentUsingLibraries likePhpMailer.4) smtpauthenticimprpr

PHP & SMTP와 함께 이메일 보내기 안내서PHP & SMTP와 함께 이메일 보내기 안내서May 09, 2025 am 12:06 AM

PHP 및 SMTP를 사용하여 메일을 보내는 것은 PHPMailer 라이브러리를 통해 달성 할 수 있습니다. 1) phpmailer 설치 및 구성, 2) SMTP 서버 세부 정보 설정, 3) 이메일 컨텐츠 정의, 4) 이메일 보내기 및 손잡이 오류. 이 방법을 사용하여 이메일의 신뢰성과 보안을 보장하십시오.

PHP를 사용하여 이메일을 보내는 가장 좋은 방법은 무엇입니까?PHP를 사용하여 이메일을 보내는 가장 좋은 방법은 무엇입니까?May 08, 2025 am 12:21 AM

TheBesteptroachForendingeMailsInphPisusingThephPmailerlibraryDuetoitsReliability, featurerichness 및 reaseofuse.phpmailersupportssmtp, proversDetailErrorHandling, supportSattachments, andenhancessecurity.foroptimalu

PHP의 종속성 주입을위한 모범 사례PHP의 종속성 주입을위한 모범 사례May 08, 2025 am 12:21 AM

의존성 주입 (DI)을 사용하는 이유는 코드의 느슨한 커플 링, 테스트 가능성 및 유지 관리 가능성을 촉진하기 때문입니다. 1) 생성자를 사용하여 종속성을 주입하고, 2) 서비스 로케이터 사용을 피하고, 3) 종속성 주입 컨테이너를 사용하여 종속성을 관리하고, 4) 주입 종속성을 통한 테스트 가능성을 향상 시키십시오.

PHP 성능 튜닝 팁 및 요령PHP 성능 튜닝 팁 및 요령May 08, 2025 am 12:20 AM

phpperformancetuningiscrucialbecauseitenhancesspeedandefficies, thearevitalforwebapplications.1) cachingsdatabaseloadandimprovesResponsetimes.2) 최적화 된 databasequerieseiesecessarycolumnsingpeedsupedsupeveval.

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

맨티스BT

맨티스BT

Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

Atom Editor Mac 버전 다운로드

Atom Editor Mac 버전 다운로드

가장 인기 있는 오픈 소스 편집기

DVWA

DVWA

DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

WebStorm Mac 버전

WebStorm Mac 버전

유용한 JavaScript 개발 도구

에디트플러스 중국어 크랙 버전

에디트플러스 중국어 크랙 버전

작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음