get_template_directory () vs bloginfo ( 'template_directory') vs TEMPLATEPATH


16

나는이 기사를 읽었습니다 : 일반적인 WordPress 개발 실수 및 해결 방법 , 저자는 말합니다 :

테마 위치 가져 오기 : TEMPLATEPATH 또는 bloginfo ( 'template_directory')를 사용중인 경우. 중지! 위의 예제에서 볼 수 있듯이 매우 유용한 get_template_directory ()를 사용해야합니다.

그러나 그는 정교하지 않습니다. 뭐가 그렇게 나쁜 bloginfo()거야?

답변:


17

긴 이야기를 짧게 만들려면 다음 get_bloginfo( 'template_directory' )get_bloginfo( 'template_url' )단순히 반환 get_template_directory_uri().

따라서 후자의 템플릿 태그를 직접 참조하여 두 번째 통화를 바로 가기로 할 수 있습니다.

에 대한 소스를 참조하십시오get_bloginfo() .

다른 몇 가지 :

  • 'url' => home_url()
  • 'wpurl' => site_url()
  • 'stylesheet_url' => get_stylesheet_uri()
  • 'stylesheet_directory' => get_stylesheet_directory_uri()
  • 'locale' => get_locale()

편집하다

참고 사항 : TEMPLATEPATHSTYLESHEETPATHdeprecation 용으로 예정 되어 있으므로 현재 get_template_directory()get_stylesheet_directory()로 각각 교체하는 것이 좋습니다 .

편집 2

다시 :이 의견

내가 말하려고했던 것 :). get_template_directory()경로와 get_template_directory_uri()URL 을 반환하는 것을 추가하고 싶습니다 . 그래서 저자는 일관되지 않는 : get_bloginfo( 'template_directory' )그리고 get_template_directory()다른 일을 반환!

다시 소스를 참조하십시오 :)

case 'template_directory':
case 'template_url':
    $output = get_template_directory_uri();
    break;

다시 :이 의견 :

자식 테마를 개발할 때주의해야 할 점은 get_stylesheet_directory()명시 적으로 사용해야 합니다. 내가 틀렸다면 누군가 나를 교정합니다.

사실이지만 항상 그렇습니다. get_bloginfo()반환하지 않습니다 어떤 관련을 get_stylesheet_directory(). get_stylesheet_uri()and 만 반환합니다 get_stylesheet_directory_uri().


자식 테마를 개발할 때주의해야 할 점은 get_stylesheet_directory ()를 명시 적으로 사용해야합니다. 내가 틀렸다면 누군가 나를 교정합니다.
Steve

감사! 나는 왜 WP가 다른 함수를 호출하는 이러한 많은 함수들을 가지고 있는지 궁금해서 우리가 사용하지 말아야한다고 생각한다.
coopersita

이 경우 그 이유는 단순히 get_bloginfo()매개 변수 와의 호환성을 유지하기위한 것이라고 생각합니다 .
칩 베넷
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.