0

I have set up a custom rss template and all is working good but I am trying to figure out how to not show the image that is in the content. Is there a way to strip this out?

<?php
/*
Template Name: Custom Feed
*/


$numposts = 10;

function acustom_rss_date( $timestamp = null ) {
$timestamp = ($timestamp==null) ? time() : $timestamp;
echo date(DATE_RSS, $timestamp);
}

function acustom_rss_text_limit($string, $length, $replacer = '...') { 
 if(strlen($string) > $length) 
 return (preg_match('/^(.*)\W.*$/', substr($string, 0, $length+1), $matches)     ? $matches[1] : substr($string, 0, $length)) . $replacer;   
return $string; 
 }

$posts = query_posts('showposts='.$numposts);

$lastpost = $numposts - 1;

header("Content-Type: application/rss+xml; charset=UTF-8");
echo '<?xml version="1.0"?>';
?><rss version="2.0" xmlns:media="http://search.yahoo.com/mrss">
<channel>
<title>Site E-mail Update</title>
<link>http://www.example.com/</link>
<description>The latest posts from example.com</description>
<language>en-us</language>
<pubDate><?php acustom_rss_date( strtotime($ps[$lastpost]->post_date_gmt) );  ?></pubDate>
 <lastBuildDate><?php acustom_rss_date(    strtotime($ps[$lastpost]->post_date_gmt) ); ?></lastBuildDate>
<?php foreach ($posts as $post) { ?>
  <item>
 <title><?php echo get_the_title($post->ID); ?></title>

  <link><?php echo get_permalink($post->ID); ?></link>
  <?php if(get_the_post_thumbnail()): ?>
   <media:content url="<?php $image =  wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium'); echo  $image[0]; ?>" medium="image" />
<?php endif; ?>
 <author> <?php echo get_the_author_meta( 'display_name', $post->post_author  ); ?></author>

  <description>


  <?php echo '<![CDATA['.acustom_rss_text_limit($post->post_content,  500).'<br/><br/><a href="'.get_permalink($post->ID).'"> Continue Reading.  </a>'.']]>';  ?>



  </description>

  <pubDate><?php acustom_rss_date( strtotime($post->post_date_gmt) );  ?></pubDate>


  <guid><?php echo get_permalink($post->ID); ?></guid>
  </item>
 <?php } ?>
</channel>
</rss>
0

You can get rid of this code

<?php if(get_the_post_thumbnail()): ?>
   <media:content url="<?php $image =  wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium'); echo  $image[0]; ?>" medium="image" />
<?php endif; ?>

That should remove the image associated with the post. It is checking to see if the featured image is set, and then if it is, it displays it. Removing the code, removes the image from display.

  • Did this work for you? – sk03 Sep 8 '17 at 1:36
  • Did this work for you? @sdesign – sk03 Jan 31 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.