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() –