今天在Q群看见有人在问这个问题,给解决了一下顺便记录以备后用。
/**********************************
*
*
* Exploit 2016-10-14
* 根据wordpress自带图集功能
* 生成的简码获取图片附件的url
*
***************************************/
function replace_text_wp_2016_10_14($text){
preg_match('/ids="(.*?)"]/',$text,$matched);
$replace = array(
// '关键词' => '替换的关键词'
'[ gallery' => '<!--[ gallery',
'"]' => '"]-->',
);
$text = str_replace(array_keys($replace), $replace, $text);
$array_test = explode(',', $matched[1]);
foreach ($array_test as $key => $value) {
echo wp_get_attachment_url($value).'<br>';
}
return $text;
}
add_filter('the_content', 'replace_text_wp_2016_10_14');
add_filter('the_excerpt', 'replace_text_wp_2016_10_14');