2016-05-07 11 views
0

の解決策を見つけようとしています。を削除してください。 http://website/drinks/、次にハッシュタグをカテゴリの先頭に追加します。 #coffeeWordPress:カテゴリスラッグ名にハッシュタグを追加

現状:

<ul> 
<li class="cat-item-1"><a href="http://website/drinks/coffee/">Coffee</a></li> 
<li class="cat-item-2"><a href="http://website/drinks/tea/">Tea</a></li> 
</ul> 

理想の状況:

<ul> 
<li class="cat-item-1"><a href="#coffee">Coffee</a></li> 
<li class="cat-item-2"><a href="#tea">Tea</a></li> 
</ul> 


ソリューションは私のワードプレスのテーマののfunctions.phpにcoddedする必要があります。私はコーディングではマスターではありませんが、URLの終わりにハッシュを追加する方法を確立しました。

add_filter('wp_list_categories', 'filter_categories', 10, 2); 

function filter_categories($output, $args=array()){ 
     return preg_replace('/(\<a\shref=\"?[^\>]+?)\"/', '$1#"', $output); 
} 

出力:

<ul> 
<li class="cat-item-1"><a href="http://website/drinks/coffee/#">Coffee</a></li> 
<li class="cat-item-2"><a href="http://website/drinks/tea/#">tea</a></li> 
</ul> 

は、残念ながら、これは離れて私の希望状況からです...誰も私を助けてくださいことはできますか?

答えて

1

はこれを試してみてください:

add_filter('wp_list_categories', function($html, $args) { 

    $pattern = '/https?:\/\/([^\/]+)\/([^\/]+)\/?/'; 

    $html = preg_replace($pattern, '#', $html); 

    return preg_replace('/\/["\']/', '"', $html); 

}, 10, 2); 
+0

こんにちはダン、ありがとううわー!これはまさに私が探しているものです! :) –

関連する問題