我正在尝试将过滤器添加到我的 wordpress 内容的特殊 div
确定我的插件代码现在将影响所有帖子内容,但我需要的是仅将其应用于特殊的div class="game_req"而不是其他 div ex。div 类= " how_to_play"
我的帖子结构:
<div>
..........
<div class="game_req"> <!-- i need to apply filter to only this div -->
- ball : is a round ..........
- key : is what we need to ..........
- caw : is an animal ..........
</div>
<div class="how_to_play">
1- use the key to open .......
2- use ball to ........
3- use caw to .........
</div>
<div class="sss">
.... key .......
.... ball to ........
.... caw .........
</div>
..........
</div>
我的插件过滤器:
function myReplace_function($content){
$patterns = array(
'/\bball\b/',
'/\bkey\b/',
'/\bcaw\b/'
);
$replacements = array(
'ball ( <img src="smallImgs/ball.png" alt="ball"/> )',
'key ( <img src="smallImgs/key.png" alt="key"/> )',
'caw ( <img src="smallImgs/caw.png" alt="caw"/> )'
);
return preg_replace($patterns,$replacements,$content);
}
add_filter('the_content','myReplace_function');