2011-11-10 4 views
7

私はLessを使って最初のWordPressテーマを作成しました。wp_enqueue_styleとrelはスタイルシート以外ですか?

私は何をする

wp_register_style('screen_css', get_bloginfo('template_url') . '/css/screen.less', array(), false, 'screen'); 
wp_enqueue_style('screen_css'); 

私のfunctions.phpにそのようなスクリプトを使用することで、結果はということです:=質問がある

<link rel='stylesheet' id='stigma_screen-css' href='http://www.stigmahost.dch/wp-content/themes/stigmahost/css/screen.less?ver=1.0' type='text/css' media='screen' /> 

、私は何とかRELを変更することができますwp_register_style()関数を使用すると "stylesheet"ですか?

+0

)は関数wp_register_styleのどちらも(もwp_enqueue_style()あなたはrel属性を設定できますが、あなたがしようとしているものに詳細情報を提供できる場合達成するには、おそらく私は回避策を提供することができますか? – brandwaffle

答えて

7

どちらの関数もその値を渡すことはできませんが、style_loader_tagフィルタでレンダリングする前にタグにアクセスできます。このようなことをすれば...

add_filter('style_loader_tag', 'my_style_loader_tag_function'); 

function my_style_loader_tag_function($tag){ 
    //do stuff here to find and replace the rel attribute 

    return $tag; 
} 

... rel属性を任意のものに置き換えることができます。このフィルタはHTML全体としてタグとして渡されるので、preg_replace()やそれに似た何らかの処理を行い、必要な値に置き換えてください。また、このフィルタはスタイルシートをエンキューするたびに実行されるので、rel属性を変更する前に適切なもの(preg_match()など)を持っていることをテストしてください。

+0

非常にクールなアプローチ! Thansk :) –

3

私はこれが古いqであることを知っていますが、これを理解するのに役立ちました。 brandwaffleの答えからの借入、ここで私が使用したフル機能です:

function childtheme_scripts() { 

wp_enqueue_style('less',get_stylesheet_directory_uri() .'/style.less'); 
add_filter('style_loader_tag', 'my_style_loader_tag_function'); 

wp_enqueue_script('less',get_stylesheet_directory_uri() .'/jscripts/less-1.3.0.min.js', false,'1.3.0'); 

} 
add_action('wp_enqueue_scripts','childtheme_scripts', 1); 


function my_style_loader_tag_function($tag){ 
    //do stuff here to find and replace the rel attribute  
    return preg_replace("/='stylesheet' id='less-css'/", "='stylesheet/less' id='less-css'", $tag); 
} 
+0

jQuery AFAIKを必要としないでください。依存関係の配列には –

+0

があります。編集します。 – helgatheviking

関連する問題