We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41970
    • 79 Posts
    I am still trying to make this Facebook Sharing work on my single-page website:

    http://stage.pricklybaymarina.com/index.php#specialeventsContainer

    At the moment I have an iframe with meta tags for og:image, og:description and og:title, and I load them with renderResources, but for some reason, the sharing still doesn't take the og's the way it's supposed to.

    This is driving me crazy, can anybody help me of how to solve this, and get this to work properly?

    Thank you!!
      • 46886
      • 1,154 Posts
      Pls show some code for people to understand better. I started to try and figure this out but got distracted. Did you make the facebook app to get the app code? That's where I hit the wall.

      I thought the og: just needed to be in the meta tags in the header...

      Also do you get no data taken by facebook or its somehow wrong? What is the behavior like?
        • 41970
        • 79 Posts
        I tried to use the Articles package, but this never worked, some kind of bug I think, so I implemented those articles into the main page with an iframe. I know, it's an awful solution, but since the article needs to be on a separate page in order for the FB share to work properly, and take the meta tags, this is what I came up with.

        So I have a container page for the special events articles, which is being loaded into the main page (= single page website). This is the template chunk:

        <div id="specialeventsContainer">
            
          <div class="contentslideshow">
            [[!getImageList? &tvname=`contentSlider` &tpl=`tpl_contentSlider`]]
            
          </div>
            
              <div class="goHome"><a href="#homeContainer" id="goHomeBtn" title="Home"></a></div>
              <h1 class="contentheader"><span>Entertainment</span></h1>
              <h2>[[*pagetitle]]</h2>
        
          	<div id="specialeventsContent">
                
                <div class="content">
                  [[!renderResources? &parents=`67` &tpl=`specialevents_tpl`]]
                </div>      
              </div>     
        </div>


        The template chunk (specialevents_tpl):


        <script language="javascript" type="text/javascript">
          function resizeIframe(obj) {
            obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
          }
        </script>
        
        
        <iframe class="iframe1" width="100%" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="[[*id]]" onload="javascript:resizeIframe(this);">
        
        </iframe>
        


        The template for the articles:

        <html>
        <head>
        <base href="[[!++site_url]]" />
        <title>[[++site_name]] - [[*articleHeadline]]</title>
        <meta property="og:image" content="[[*roundImage]]" /> 
        <meta property="og:title" content="[[*articleHeadline]]" /> 
        <meta property="og:description" content="[[*articleText:strip_tags]]" /> 
        <meta property="og:url" content="[[++site_url]]index.php#specialeventsContainer" />
        [[$fbshare]]
        [[$specialEventsCSS]]
        [[$specialEventsJS]]
        [[$googleAnalyticsJS]]
        [[$colorboxJS]]
        [[$slideToggleJS]]
        </head>
        <body>
        
        <div class="contentLeft iframe">
        <div class="roundimage">
        <img class="round" src="[[*roundImage:phpthumbof=`w=170&h=170&zc=1&q=95`]]" alt="[[*articleHeadline]]" />
        </div>
        
        <a class="fbsharebutton" id="shareFB" href="https://www.facebook.com/sharer/sharer.php?u='http://aaa.com/#/project/xbox-branding'&t=TITLE"
           onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;"   target="_blank" title="Share on Facebook">Share on Facebook</a>
        <script type="text/javascript">document.getElementById("shareFB").setAttribute("href", "https://www.facebook.com/sharer/sharer.php?u=" + document.URL);</script>
        
                <h4 class="blue" style="margin-bottom:10px; margin-top:0;">[[*articleHeadline]]</h4>
                <p class="datetext">[[*datetimeText]]</p>
                [[*articleText]]
           <div class="divider"></div>
        </div>
        </body>
        </html>


        So as you see, I included the og tags into the article pages, so it should work (at least from my way of understanding).
        But it doesn't use the meta tags at all, so I don't know what the problem is. I didn't use the FB app.
          • 42046
          • 436 Posts
          One thing to keep in mind is once FB generates a preview for your page, it will cache and re-use that rather than generating a new one each time, so changes in the meta data won't show up every time. I have found you can re-fresh their cached one using the dev tools og debugger: https://developers.facebook.com/tools/debug/
            • 46886
            • 1,154 Posts
            Ok thanks for the code, its a bit clearer now what you are trying to do.

            I am going to jump on this first thing tomorrow morning. I need to do this myself anyway, been slacking on it. Hopefully someone better than me can jump in too. I got about halfway done with it...

            Also pls have a look at Menno's work here: https://github.com/DESIGNfromWITHIN/social-sharing-modx

            Its got a lot of useful code.

            For now the one thing I notice is that you have the meta contents but also your button code has places to put content too, and it seems to be a problem here:

            <a class="fbsharebutton" id="shareFB" href="https://www.facebook.com/sharer/sharer.php?u='http://aaa.com/#/project/xbox-branding'&t=TITLE"
               onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;"   target="_blank" title="Share on Facebook">Share on Facebook</a>
            <script type="text/javascript">document.getElementById("shareFB").setAttribute("href", "https://www.facebook.com/sharer/sharer.php?u=" + document.URL);</script>


            This seems a bit muddled to me. Here is what I have right now, and while I stopped before it worked perfectly, some of the right contents was getting in there:

            <a target="_blank" href="http://www.facebook.com/sharer/sharer.php?u=[[+url]]"><img src="facebook.png" /></a>


            However I believe it isn't possible to add other data like title or contents to this code...again I will take a good look at this tomorrow. Its hard to find a simple solution when searching online.
              • 41970
              • 79 Posts
              Thank you for also looking into this! Just wanted to let you know that I'll look into it some further with a developer friend of mine, and I hope he can shed some light on the missing og's. I will post again here tonight, after I know more.
                • 41970
                • 79 Posts
                Update:


                I used nuan88's FB sharing link and adjusted it, and now it works:

                <a class="fbsharebutton" id="shareFB" target="_blank" href="http://www.facebook.com/sharer/sharer.php?u=[[++site_url]][[*id]]" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;"   target="_blank" title="Share on Facebook"></a>


                It finally takes the meta's I included, but the only thing that I still have to fix is the link back from Facebook to the article. I'll work on that some more tonight, and will post an update once I figured this out.
                Thank you nuan88 for helping me with this!!
                  • 46886
                  • 1,154 Posts
                  Ok sounds good, I am sure we can come up with a solution fairly soon.

                  One last point, the sharer code we are using right now will send the url (and we hope more) to facebook so users can share your contents, but this button may not be connected with the meta tags.

                  What I mean is this, and I might be totally wrong here: If you have the meta contents in your header, and you make a new FB post and paste in the link to your site, (not using the share button) as I understand FB will go to your site (well, that page) and grab the contents from the meta tags.

                  So when I see an article I like, I want to tell my friends about it, and so I go to FB and paste in the url, and then FB reads the meta tags and adds in the title, related picture and summary. So you could check to see if that works and FB can see the right contents.
                    • 46886
                    • 1,154 Posts
                    Wow! Great job!

                    For url redirecting, you might try redirect_uri

                    target="_blank" redirect_uri="www.sitename.com" title="Share on Facebook"></a>

                    Also I notice a couple extra spaces before target, those are ok?

                    But important thing it is grabbing the metas, I wonder what did the trick. But still, very cool!
                      • 46886
                      • 1,154 Posts
                      Oops looks like you have target="_blank" in there twice. Otherwise looks pretty good!