2013-10-22 15 views
1

在WordPress的,如果我使用此代碼添加「相冊」我的主題模板:WordPress - 如何從function.php中禁用media.php使用的過濾器?

   <?php echo do_shortcode('[gallery link="file"]'); ?> 

然後WordPress的核心將「use_default_gallery_style」導致其設置爲「真正」中:

WP-包括/線忽略原始開始755等:

if (apply_filters('use_default_gallery_style', true)) 
    $gallery_style = " 
    <style type='text/css'> 
     #{$selector} { 
      margin: auto; 
     } 
     #{$selector} .gallery-item { 
      float: {$float}; 
      margin-top: 10px; 
      text-align: center; 
      width: {$itemwidth}%; 
     } 
     #{$selector} img { 
      border: 2px solid #cfcfcf; 
     } 
     #{$selector} .gallery-caption { 
      margin-left: 0; 
     } 
     /* see gallery_shortcode() in wp-includes/media.php */ 
    </style>"; 
$size_class = sanitize_html_class($size); 
$gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>"; 
$output = apply_filters('gallery_style', $gallery_style . "\n\t\t" . $gallery_div); 

問題是:我的頁面的HTML代碼將無法通過在線HTML驗證器驗證,導致WordPress Core在HTML頁面中打印CSS,它不使用分離的CSS文件,這是正確的方法。

代碼WordPress的輸出,以HTML的樣子:

<style type='text/css'> 
      #gallery-1 { 
       margin: auto; 
      } 
      #gallery-1 .gallery-item { 
       float: left; 
       margin-top: 10px; 
       text-align: center; 
       width: 33%; 
      } 
      #gallery-1 img { 
       border: 2px solid #cfcfcf; 
      } 
      #gallery-1 .gallery-caption { 
       margin-left: 0; 
      } 
      /* see gallery_shortcode() in wp-includes/media.php */ 
     </style> 

我現在的解決方案:

我知道它不建議編輯WordPress的核心文件!但我有編輯WP-包括/線忽略原始755

來源:

 if (apply_filters('use_default_gallery_style', true)) 

要:

 if (apply_filters('use_default_gallery_style', false)) 

我已經更新/添加到了我的風格.css:

 #gallery-1 { 
      margin: auto; 
     } 
     #gallery-1 .gallery-item { 
      float: left; 
      margin-top: 10px; 
      text-align: center; 
      width: 33%; 
     } 
     #gallery-1 img { 
      border: 2px solid #cfcfcf; 
     } 
     #gallery-1 .gallery-caption { 
      margin-left: 0; 
     } 

我的問題:如何使用function.php將filter:use_default_gallery_style設置爲false?

如何在function.php中編寫鉤子,函數或動作來刪除或設置use_default_gallery_style爲false?

最好的辦法是做什麼?

如果有人可以幫助我或引導我使用這個功能,那麼我很新,不想搞亂WordPress的CORE文件,這將是非常棒的。

在此先感謝:d

+4

這個問題似乎是題外話,因爲它是關於WordPress的,屬於爲http:// wordpress.stackexchange.com – Raptor

回答