1

I'm trying to style the RSS feed that the user would see. So all all they would see is the image from the post, the text from the WYSIWYG editor and a button that's part of the theme.

Here is the button from the single.php template file:

<div class="bottomgift clearfix">
<a target="_blank" rel="nofollow" href="<?php getCustomField('Affiliate Link'); ?>" class="go-button">Go</a>
</div>

How do I add all this to style the RSS feed?

In Functions.php

function modRSS($content) {
   global $post;

   if ( has_post_thumbnail( $post->ID ) ){
      $content = '<div>' . get_the_post_thumbnail( $post->ID, 'full', array( 'style' => 'margin-bottom: 15px;' ) ) . '</div>' . $content;
   }

   $content = $content . '<a href="' . getCustomField('Affiliate Link') . '">Go</a>';

   return $content;
}

add_filter('the_excerpt_rss', 'modRSS');
add_filter('the_content_feed', 'modRSS');
Joe Bobby
  • 2,803
  • 10
  • 40
  • 59

1 Answers1

1

You can prepend or amend any syntax to WordPress RSS feeds quite easily.

Here is some code to do that take from here... http://webdesignzo.com/show-featured-images-in-rss-feed-feedburner/ modified a little for your purposes.

function modRSS($content) {
   global $post;

   if ( has_post_thumbnail( $post->ID ) ){
      $content = '<div>' . get_the_post_thumbnail( $post->ID, 'thumbnail', array( 'style' => 'margin-bottom: 15px;' ) ) . '</div>' . $content;
   }

   $content = $content . '<div class="bottomgift clearfix"><a target="_blank" rel="nofollow" href="' . getCustomField('Affiliate Link') . '" class="go-button">Go</a</div>';

   //Adding Custom Fields
   $content = $content . get_post_meta($post->ID,'custom_field_name', true);

   return $content;
}

add_filter('the_excerpt_rss', 'modRSS');
add_filter('the_content_feed', 'modRSS');

My code is untested but something like this should be what you are looking for.

P.S. This isn't styling per say as your question title suggests, but more adding markup to it.

Foxinni
  • 3,980
  • 2
  • 26
  • 26
  • I'll try this out today when I get back to my computer and let you know how it goes! thanks! – Joe Bobby Jul 24 '12 at 15:20
  • waiting for a response from the client regarding how the RSS is setup, but when I pasted your code into the functions.php I got a error in functions.php on line 55 which was where I pasted your code. I tested the one from the site you linked so that does work, but the issue is the RSS isn't updating when I make a new post so I'm not able to test and see if it works yet and thats why there has been a delay. Should get a response today and then I'll let you know how it goes thanks! – Joe Bobby Jul 30 '12 at 17:48
  • It looks like I had a curly bracket to many. Updated my code. It's possible that the browser is caching the RSS too. Force refreshing might work. – Foxinni Jul 31 '12 at 12:57
  • this is suppose to be pasted in the functions.php right? I've tried the code you pasted above and from the other site and it seems they both stop the RSS from working completely.. any idea why? – Joe Bobby Jul 31 '12 at 20:04
  • everything is working now but the custom field.. I found this http://www.wpbeginner.com/wp-tutorials/how-to-add-content-and-completely-manipulate-your-wordpress-rss-feeds/ under number 1 it says how to add a custom field, but I don't know what to change with what I have already above – Joe Bobby Aug 03 '12 at 03:08
  • You already have the $post object. So to get a custom field from that just use `get_post_meta($post->ID,'custom_field_name', true);` How exactly it should be used in your code will take bit of playing and basic understanding of php from your part. I've edited the example again so you can see. – Foxinni Aug 03 '12 at 11:31
  • everything is working fine, its just the link entered in the post for `getCustomField('Affiliate Link')` is appearing at the very top instead of inside `href=""` for the "Go" link.. any idea why its not appearing inside? – Joe Bobby Aug 07 '12 at 18:34
  • The `getCustomField` function echo's out by default (I assume). You will want it to return the value instead so you echo it out afterwards. So go look at the `getCustomField` function and make it `return $customField` and not `echo $customField` so you can use `'someString ' . getCustomField('Affiliate Link') . ' endOfString';` in a way that is does not echo, but return the custom field value. – Foxinni Aug 08 '12 at 08:39
  • Sorry its taking me a bit to grasp this, a little frustrating! So by what your saying, if I don't tell it to return the value it will automatically echo.. but if you look at the new php code i readded to my first post it says `$content = $content . 'Go';` and then it says right under that `return $content;`.. I don't understand php that well so its a little difficult for me sorry this is taking so long! – Joe Bobby Aug 08 '12 at 13:48
  • The `getCustomField()` function itself echoes. If you added the `getCustomField('Affiliate Link')` just the top of your functions.php then it's not supposed to output anything, but because it does you have to modify the original `getCustomField()` function. Unless i'm wrong. You need to understand the basics on PHP about echo and return. http://stackoverflow.com/questions/9387765/what-is-the-difference-between-php-echo-and-php-return-in-plain-english – Foxinni Aug 08 '12 at 14:05
  • Ah I see.. After clicking that link I understand the difference between echo and return now.. so the function is echoing the value before i need it.. And I didnt add `getCustomField('Affiliate Link')` to the top of functions.php I have the chunk of code you suggested at the very bottom right before the closing `?>` tag. If I don't want getCustomField() to automatically echo, how do I get it to return the value I need so it displays the URL in the "Go" link? – Joe Bobby Aug 08 '12 at 18:22