1
我想在WordPress中更新the_content_rss
以便它适合feedburner。它需要找到每个img标签,看它是否有宽度和高度设置。如果它们大于600,它们应该减少到600.如果它们没有设置,那么宽度应该设置为600.我想使用一些代码here来做到这一点,但我有点卡住了,我会感激帮助修复它。在Wordpress Feed中调整img标签的大小
问题:
- 是否行得通?
它如何找到如果宽度为空 - 在哪种情况下添加它?
<?php function feedburner_img_resize($the_content) { // Create a new istance of DOMDocument $post = new DOMDocument(); // Load $the_content as HTML $post->loadHTML($the_content); // Look up for all the <img> tags. $imgs = $post->getElementsByTagName('img'); // Iteration time foreach($imgs as $img) { // if width is smaller than 600 - no need to continue $width = $img->getAttribute('width'); if($width < 600) continue; $img->removeAttribute('width'); $img->setAttribute('width', 600); $img->removeAttribute('height'); // so the image is not distorted }; return $post->saveHTML(); } add_filter('the_content_rss', 'feedburner_img_resize'); ?>
考虑使用javascript? –
我需要改变它使用PHP为了更新add_filter ... –
我不是很熟悉wordpress,但你可以做一个ajax请求,然后将它传递到PHP和add_filter() –