我使用Wordpress for AngularJS作为后端(wp json插件),实际上我为主题制作的结构是这样的
myApptheme
-style.css //nothing special here just inits the theme
-index.php
-header.php
-functions.php
lib //here some overrides php
--gallery.php
app //holds the angular stuff generated with yo angular
bower_components //bower packages what I need
在画廊里。php(这是我从roots借来的,有自己的修改)我添加了Masony所需的标记,并尝试过滤我的库项目,并为引导添加自定义类(img responsive)。代码段如下所示。
/**
* Add class="img-responsive" to attachment items
*/
function responsive_attachment_link_class($html) {
$classes = \'img-responsive\'; // separated by spaces, e.g. \'img image-link\'
// check if there are already classes assigned to the anchor
if ( preg_match(\'/<img.*? class="/\', $html) ) {
$html = preg_replace(\'/(<img.*? class=" .*?)(".*?\\="">)/\', \'$1 \' . $classes . \' $2\', $html);
} else {
$html = preg_replace(\'/(<img.*?)(\\>)/\', \'$1 class="\' . $classes . \'" $2\', $html);
}
// remove dimensions from images,, does not need it!
$html = preg_replace( \'/(width|height)=\\"\\d*\\"\\s/\', "", $html );
return $html;
}
add_filter(\'wp_get_attachment_link\', \'responsive_attachment_link_class\');
正在删除
img width|heigh
t起作用,但类重写不起作用。这些代码有什么问题?
actual output
<img alt="ind018" class="attachment-large" src="http://wp.local/wp-content/uploads/2014/08/ind018-728x1024.jpeg">
expected
<img alt="ind018" class="img-responsive" src="http://wp.local/wp-content/uploads/2014/08/ind018-728x1024.jpeg">