GHOST default RSS is not fully compatible with Facebook Instant articles, so I created a one

My News website is running with Ghost and the default RSS feed was not fully compatible with Facebook Instant articles. Therefore every time I have to edit production articles to include the following.

  1. op-ad
  2. fb:use_automatic_ad_placement
  3. Google Analytics integration
  4. op-kicker
  5. Author

And there were some more changes that I have to done. I have done this for few days and I decided to create a custom RSS feed that fully supports Facebook Instant Articles. So I studied a few WordPress websites’ RSS feeds that have Instant Article approval. After that, I created my custom RSS feed and it worked.

Now I came here to share it with you.

<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        <title>{{@site.title}} </title>
        <description>{{@site.description}}</description>
        <link>{{@site.url}}</link>
        <image>
            <url>{{@site.url}}/favicon.png</url>
            <title>{{@site.title}}</title>
            <link>{{@site.url}}</link>
        </image>
        <lastBuildDate>{{date format="ddd, DD MMM YYYY HH:mm:ss ZZ"}}</lastBuildDate>
        <atom:link href="{{@site.url}}" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>

        {{#get "posts" limit="15" include="authors,tags"}}
        {{#foreach posts}}
        <item>
            <title>
                <![CDATA[ {{title}} ]]>
            </title>
            <link>{{url absolute="true"}}</link>
            <description>
                <![CDATA[ {{excerpt}} ]]>
            </description>
            <content:encoded>
                <![CDATA[                 
                    <html>
                        <head>
                            <link rel="canonical" href="{{url absolute=" true"}}" />
                            <meta charset="utf-8" />
                            <meta property="op:generator" content="facebook-instant-articles-sdk-php" />
                            <meta property="op:generator:version" content="1.10.0" />
                            <meta property="op:generator:application:version" content="4.2.1" />
                            <meta property="op:generator:transformer" content="facebook-instant-articles-sdk-php" />
                            <meta property="op:generator:transformer:version" content="1.10.0" />
                            <meta property="op:markup_version" content="v1.0" />
                            <meta property="fb:use_automatic_ad_placement" content="enable=true ad_density=default" />
                            <meta property="fb:article_style" content="default" />
                            <meta property="fb:use_automatic_ad_placement" content="enable=true ad_density=default">
                        </head>

                        <body>
                            <article>
                                <header>
                                    <figure><img src="{{feature_image}}" alt="{{title}}"></figure>
                                    <h1>{{title}}</h1>
                                    <address><a>{{primary_author.name}}</a></address>
                                    <h3 class="op-kicker">{{primary_tag.name}}</h3>
                                    <meta property="fb:use_automatic_ad_placement" content="enable=true ad_density=default">
                                    <figure class="op-ad"><iframe
                                            src="https://www.facebook.com/adnw_request?placement=placement_id&adtype=banner300x250"
                                            width="300" height="250"></iframe></figure>
                                </header>
                                {{content}}
                                <footer></footer>
                                <figure class="op-tracker">
                                    <iframe>
                                       TRACKING_CODE
                                    </iframe>
                                </figure>
                            </article>
                        </body>
                    </html>]]>

            </content:encoded>
            <guid isPermaLink="false">{{id}}</guid>
            <pubDate>{{date format="ddd, DD MMM YYYY HH:mm:ss ZZ"}}</pubDate>
            <author>{{primary_author.name}}</author>
        </item>
        {{/foreach}}
        {{/get}}

    </channel>
</rss>

You have to do is follow the Custom RSS + Ghost guide and replace my RSS code.

Audience Network Ad tag Sample
You can find PLACEMENT_ID at your Facebook Audience network. Please replace it to show ads in your Instant articles.

<figure class="op-ad">
  <iframe width="300" height="250" style="border:0; margin:0;" src="https://www.facebook.com/adnw_request?placement=PLACEMENT_ID&adtype=banner300x250"></iframe>
</figure>

Google Analytics
Add your Google Analytics tracking code for TRACKING_CODE

<figure class="op-tracker">
    <iframe>
        TRACKING_CODE
    </iframe>
</figure>

That’s all. If you want to look at my Instant article RSS, please visit https://androidwedakarayo.com/instant

I would like to invite Ghost creators to add this as another RSS feed that supports Facebook Instant articles because if someone tries to get Instant Article approval using {{site.url}}/rss, he/she have to do some work to correct production articles. If you can add this as another RSS feed like, {{site.ur}}/feed/instant-articles it will be very easy to Ghost beginners.