Forum

Thread tagged as: Question, Meta, Blog

Meta Data in Blogs

Hi, I'm working on the SEO for a blog and need some help. On each post I have added tags until the meta and social section but when I view the page source they do not appear? Code below for post.php

<?php perch_blog_post(perch_get('s')); 

       # 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'      => 'https://www.facebook.com/JohnMarkFilms',
    ));?>

global.header.php code:

    <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title><?php perch_layout_var('title'); ?></title>
      <!-- Bootstrap CSS -->
      <link rel="stylesheet" href="css/bootstrap.min.css">
      <!-- Font -->
      <link rel="stylesheet" href="css/font-awesome.min.css">
      <link rel="stylesheet" href="css/elegant-font.css">
      <link rel="stylesheet" href="css/linearicons.css">
      <!-- REVOLUTION STYLE SHEETS -->
      <link rel="stylesheet" type="text/css" href="revolution/css/settings.css">
      <!-- REVOLUTION LAYERS STYLES -->
      <link rel="stylesheet" type="text/css" href="revolution/css/layers.css">
      <!-- REVOLUTION NAVIGATION STYLES -->
      <link rel="stylesheet" type="text/css" href="revolution/css/navigation.css">
      <!-- OWL CAROUSEL
         ================================================== --> 
      <link rel="stylesheet" href="css/owl.carousel.css">
      <!-- SCROLL BAR MOBILE MENU
         ================================================== --> 
         <?php
    perch_page_attribute('description', array(
        'template' => 'seo.html'
    ));
?>

      <link rel="stylesheet" href="css/jquery.mCustomScrollbar.css" />
      <?php
    $domain        = 'https://'.$_SERVER["HTTP_HOST"];
    $url           = $domain.$_SERVER["REQUEST_URI"];
    $sitename      = "John Mark Films";
    $twittername   = "@johnmarkfilms";
    $sharing_image = '/images/collection.jpg';

    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'    
    ));
    ?>


      <!-- Main Style -->
      <link rel="stylesheet" href="style.css">
      <!-- color scheme -->
      <link rel="stylesheet" href="switcher/demo.css" type="text/css">
      <link rel="stylesheet" href="switcher/colors/yellow.css" type="text/css" id="colors">
      <!-- Favicons
         ================================================== -->
      <link rel="shortcut icon" href="favicon.png">
   </head>


Thanks!

Jade Marling

Jade Marling 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What order to these appear in?

<?php include('admin/runtime.php');?>

<!DOCTYPE html>
<html lang="">
   <?php
    $title = perch_blog_post_field(perch_get('s'), 'postTitle', true);
    perch_layout('global.header', array(
      'title'=>$title
    ));
    ?>
   <body>
<?php include('includes/analyticstracking.php'); ?>
      <?php include('includes/navigation.php');?>

            <?php perch_blog_post(perch_get('s')); 

       # 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'      => 'https://www.facebook.com/JohnMarkFilms',
    ));?>

The social is first with tags underneath. Neither are working.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Where does perch_page_attributes() get called in relation to this? After it, right?

Ah right, is that what I'm missing? I've put it in straight after perch_page_attributes_extend and still nothing

Drew McLellan

Drew McLellan 2638 points
Perch Support

You do need to actually output the page attributes, yes.

If you add <perch:showall /> to the attribute template you're using at that point, do you see your og_ values available in the template?

So now I've got

<?php include('admin/runtime.php');?>

<!DOCTYPE html>
<html lang="">
   <?php
    $title = perch_blog_post_field(perch_get('s'), 'postTitle', true);
    perch_layout('global.header', array(
      'title'=>$title
    ));




    ?>
   <body>
<?php include('includes/analyticstracking.php'); ?>
      <?php include('includes/navigation.php');?>

            <?php perch_blog_post(perch_get('s')); 

       # 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'      => 'https://www.facebook.com/JohnMarkFilms',
    ));
        perch_page_attributes(array(
        'template' => 'default.html'
    ));
       ?>

Still nothing, I do want the og values as well

Drew McLellan

Drew McLellan 2638 points
Perch Support

What does <perch:showall /> output in that default.html template?

This is default.html

    <perch:template path="pages/attributes/seo.html" />
    <perch:template path="pages/attributes/facebook.html" />
    <perch:template path="pages/attributes/twitter.html" />
<perch:showall />

seo.html

<meta name="description" content="<perch:pages id="description" label="Description" type="textarea" size="xs" escape="true" count="chars" />" />
<meta name="keywords" content="<perch:pages id="keywords" label="Keywords" type="textarea" size="xs" escape="true" help="Separate with commas" count="chars" />" />
<meta name="robots" content="<perch:pages id="noindex" label="Do not index" type="checkbox" value="noindex" append="," divider-before="Search engine indexing" /><perch:pages id="nofollow" label="Do not follow links" type="checkbox" value="nofollow" append="," /><perch:pages id="nosnippet" label="Do not show a snippet" type="checkbox" value="nosnippet" append="," />" />

facebook.html

<meta property="og:site_name" content="<perch:pages id="sitename" type="hidden" />" />
    <meta property="og:url" content="<perch:pages id="url" type="hidden" />" />
    <meta property="og:title" content="<perch:pages id="og_title" label="Social title" type="text" escape="true" help="Title for this document with no branding or site name" divider-before="Facebook Open Graph Tags" />" />
    <meta property="og:description" content="<perch:pages id="og_description" label="Social description" type="textarea" size="s" escape="true" />" />
    <perch:if exists="og_image">
    <meta property="og:image" content="<perch:pages id="domain" type="hidden" /><perch:pages id="og_image" label="Image when shared" help="Should be at least 1200x630" type="image" width="1200" />" />
    <perch:else />
    <meta property="og:image" content="<perch:pages id="domain" type="hidden" /><perch:pages id="sharing_image" type="hidden" />" />
    </perch:if>
    <perch:if exists="og_type">
    <meta property="og:type" content="<perch:pages id="og_type" label="Facebook type" type="select" options="article,book,profile,website,video,music" allowempty="true" />" />
    </perch:if>
    <perch:if exists="og_author">
    <meta property="article:author" content="<perch:pages id="og_author" type="hidden" />" />
    </perch:if>

twitter.html

<meta name="twitter:card" content="summary" />
    <meta name="twitter:site" content="<perch:pages id="twittername" type="hidden" />" />
    <meta name="twitter:title" content="<perch:pages id="og_title" label="Social title" type="text" escape="true" help="Title for this document with no branding or site name" />" />
    <meta name="twitter:description" content="<perch:pages id="og_description" label="Social description" type="textarea" size="s" escape="true" />" />
    <perch:if exists="og_image">
    <meta property="twitter:image" content="<perch:pages id="domain" type="hidden" /><perch:pages id="og_image" label="Image when shared" help="Should be at least 1200x630" type="image" width="1200" />" />
    </perch:if>
    <meta name="twitter:url" content="<perch:pages id="url" type="hidden" />" />
Drew McLellan

Drew McLellan 2638 points
Perch Support

Please let me know if I'm not being clear enough, but what does it output?

Nothing. It outsputs everything on the other pages but not the blog posts.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is it finding the template? What does debug say?

SELECT * FROM perch2_blog_posts WHERE postStatus='Published' AND postDateTime<='2017-04-06 14:25:00' AND postSlug='2017-04-03-lisa-wyn'
[23] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[1] SELECT * FROM perch2_blog_sections ORDER BY sectionTitle ASC
[1] SELECT * FROM perch2_blogs ORDER BY blogTitle ASC
Using template: /addons/apps/perch_blog/templates/blog/post.html
[1] SELECT * FROM perch2_pages WHERE pagePath='/post.php' LIMIT 1
[1] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_blog_index idx JOIN perch2_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch2_blog_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='postID' AND idx2.indexKey='_id' WHERE 1=1 AND ((idx.indexKey='postSlug' AND idx.indexValue='2017-04-03-lisa-wyn')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey ) as tbl WHERE (postStatus='Published' AND postDateTime<='2017-04-06 14:25:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 10
[1] SELECT FOUND_ROWS() AS `count`
[1] Using template: /addons/apps/perch_blog/templates/blog/post.html

Array
(
    [type] => 8
    [message] => Undefined variable: post
    [file] => /home/linweb39/j/johnmarkfilms.co.uk/user/htdocs/post.php
    [line] => 23
)
Drew McLellan

Drew McLellan 2638 points
Perch Support

What are you doing on line 23 of post.php ?

$description = strip_tags($post['0']['excerpt']);

Drew McLellan

Drew McLellan 2638 points
Perch Support

Where is $post populated? I can't see that in any of the code you've shown.

I'm not sure, I just got the code for it off the docs. What do I need to set $post as?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Where did you get it from?

I'm not really sure. I can't find it now. How do I fix it?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It looks like you're missing the start of the code - so I'm not sure what you're trying to do here.

All I want is to add meta data and og to blog posts :)