2014-01-05 5 views
0

내 Wordpress 테마에서 맞춤 템플릿이있는 맞춤 게시물 유형이 거의 없습니다. 이러한 템플릿은 특정 CSS 또는 자바 스크립트와 같은 추가 데이터를 사용합니다.wordpress에 데이터 추가 get_header()

이러한 종류의 데이터를 get_header() 함수에 추가하는 방법이 있습니까? 그렇다면 사용자 정의 게시 유형 템플릿에 하드 복사하지 않고 변경할 수 있습니까?

즉, 예를 들면. 내가 정확하게 다음 질문을 이해 한 경우이 같은 뭔가가 필요 <link rel="stylesheet" href="<?php echo get_bloginfo('template_url'); ?>/css/interview.css" type="text/css" media="all">

get_header(); 

답변

0

내부에 삽입 : -

function theme_name_scripts() { 
    global $post; 
    $post_type = get_post_type($post); 
    if($post_type === 'your-custom-post-type-slug-here') { // edit this line as per requirements 
     wp_enqueue_style('style-interview', get_bloginfo('template_url') . '/css/interview.css');  
    } 
} 
add_action('wp_enqueue_scripts', 'theme_name_scripts'); 

(감사 @TopDown 주석 성능 팁을위한.)

위의 코드를 테마의 Functions.php에두면됩니다. 추가 정보 : http://codex.wordpress.org/Function_Reference/wp_enqueue_style

+1

위에서 언급 한 기능에서 포스트 유형을 확인하여 포스트 유형에만로드해야하는 경우 http 성능을 절약 할 수 있습니다. 글로벌 $ 게시물; $ post_type = get_post_type ($ post); 그런 다음 게시물 유형 슬러그에 대한 $ post_type var을 확인하십시오. – topdown

관련 문제