2013-03-23 6 views
1

WP에서 기본 테마의 하위 테마를 사용하고 있는데 wp-admin에서 배경 이미지를 변경했습니다 ... wp_head();wordpress 사용자 정의 배경 테마 지원

<style type="text/css" id="custom-background-css"> 
    body.custom-background { background-color: #fffffe; background-image: url('http://example.com/wp-content/uploads/header.jpg'); background-repeat: no-repeat; background-position: top center; background-attachment: fixed; } 
</style> 

내가 어떤 이유로 이미지의 URL (일부 후크, functions.php 수정 또는 아무것도 다른 사람을) 수정해야하지만 난 수 없습니다입니다 : header.php의 기능은 ... 출력 소스 코드는 다음과 같습니다 이것을하는 방법을 찾으십시오. 내가 찾고있는 무엇을 eexactly 여기

답변

1

WP와의 tuts 기사의 코드는 나를 위해 작동하지 않았다,하지만 난 그것을 작동하게하는 약간의 수정을 관리

global $wp_version; 

if (! function_exists('change_custom_background_cb')) : 

function change_custom_background_cb() { 
    $background = get_background_image(); 
    $color = get_background_color(); 

    if (! $background && ! $color) 
     return; 

    $style = $color ? "background-color: #$color;" : ''; 

    if ($background) { 
     $image = " background-image: url('$background');"; 

     $repeat = get_theme_mod('background_repeat', 'repeat'); 

     if (! in_array($repeat, array('no-repeat', 'repeat-x', 'repeat-y', 'repeat'))) 
      $repeat = 'repeat'; 

     $repeat = " background-repeat: $repeat;"; 

     $position = get_theme_mod('background_position_x', 'left'); 

     if (! in_array($position, array('center', 'right', 'left'))) 
      $position = 'left'; 

     $position = " background-position: top $position;"; 

     $attachment = get_theme_mod('background_attachment', 'scroll'); 

     if (! in_array($attachment, array('fixed', 'scroll'))) 
      $attachment = 'scroll'; 

     $attachment = " background-attachment: $attachment;"; 

     $style .= $image . $repeat . $position . $attachment; 
    } 
?> 
<style type="text/css" id="custom-background-css"> 
.custom-background { <?php echo trim($style); ?> } 
</style> 
<?php 
} 
if (version_compare($wp_version, '3.4', '>=')) { 
    add_theme_support('custom-background', array('wp-head-callback' => 'change_custom_background_cb','default-color' => 'fff')); 
} 
else { 
    add_custom_background('change_custom_background_cb'); 
} 

endif; 
3

는 솔직히 말해서, 나는 팬이 아니에요. WordPress에서 조정할 수없는 기능을 y 테마. 이것이 내가 어떻게 해결 했는가. body 태그에서 custom-background 클래스를 삭제했습니다. 다행히도 여전히 유용합니다.

function disable_custom_background_css($classes) 
{ 
    $key = array_search('custom-background', $classes, true); 
    if($key !== false) 
     unset($classes[$key]); 
    return $classes; 
} 

바람직 functions.php

add_filter('body_class', 'disable_custom_background_css'); 

에, body_class()를 호출하기 전에

이 body 태그에이 특정 스타일을 추가하는 wp_head의 스크립트를 방지 할 수 있습니다. 이제 백그라운드 이미지 구현 방법을 결정할 수 있습니다.

관련 문제