Forum

Thread tagged as: Problem, Blog

Facebook og data not showing on blog posts

I’m trying to set up the Facebook go data on blog posts, I have it working fine on standard pages but I don’t anything at all from the page attributes on blog post pages.

Here is my diagnostic:

Perch: 2.8.13, PHP: 5.6.0, MySQL: 5.6.23, with PDO
Server OS: Linux, litespeed
Installed apps: content (2.8.13), assets (2.8.13), categories (2.8.13), perch_blog (4.6)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_blog', );
PERCH_LOGINPATH: /perch
PERCH_PATH: /home/helenaclayton/public_html/perch
PERCH_CORE: /home/helenaclayton/public_html/perch/core
PERCH_RESFILEPATH: /home/helenaclayton/public_html/perch/resources
Image manipulation: GD
PHP limits: Max upload 2M, Max POST 8M, Memory: 128M, Total max file upload: 2M
Resource folder writeable: Yes
HTTP_HOST: helenaclayton.co.uk
DOCUMENT_ROOT: /home/helenaclayton/public_html
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

I have this in the head of my post page:

<?php 
        # get the post
        $post = perch_blog_custom(array(
      'filter'        => 'postSlug',
      'match'         => 'eq',
      'value'         => perch_get('s'),
      'skip-template' => 'true',
      'return-html'   => 'true',
        ));

        # set up the variables
        $title       = $post['0']['postTitle'];
        $description = strip_tags($post['0']['excerpt']);
        if (isset($post[0]['fbimage'])) {
        $fbimage = $post[0]['fbimage'];
        } else {
        $fbimage = '';
        }

        # use the variables in the array value 
        perch_page_attributes_extend(array(
        'description'    => $description,
            'og_description' => $description,
            'og_title'       => $title,
            'og_type'        => 'article',
            'sharing_image'  => $fbimage,
            'og_author'      => 'Helena Clayton',
        ));

        perch_page_attributes();
    ?>
Nick Bramwell

Nick Bramwell 5 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What result do you get?

Hello Drew, it doesn’t output anything from the attributes at all, I’ve turned on debugged and there are no errors. On the non-blog pages I used:

<?php 
        $domain        = 'https://'.$_SERVER["HTTP_HOST"];
        $url           = $domain.$_SERVER["REQUEST_URI"];
        $sitename      = "Helena Clayton";
        $twittername   = "@helenaclayton";
        $sharing_image = '/images/for_facebook.jpg';

        PerchSystem::set_var('sitename',$sitename);
        PerchSystem::set_var('domain',$domain);
        PerchSystem::set_var('url',$url);
        PerchSystem::set_var('sharing_image',$sharing_image);
        PerchSystem::set_var('twittername',$twittername);

        perch_page_attributes(array(        
            'template' => 'default.html'    
        ));
    ?>

which works fine.

Both use the same template.

Drew McLellan

Drew McLellan 2638 points
Perch Support

We've just released Blog 5.0 to make this simpler. It has a dedicated section for entering Facebook and Twitter meta data, and a simple function to output it all in the head of your page.

Blog: https://grabaperch.com/add-ons/apps/blog

New page function: https://docs.grabaperch.com/addons/blog/page-functions/perch-blog-post-meta/