Forum

Thread tagged as: Problem, Blog

Meta Titles & Descriptions not working on blog

I have got it working on normal page but on BlogApp it is not working is there.

<?php
  if (perch_layout_has('blog-post')) {
      perch_blog_post_meta(perch_get('s'));
      perch_page_attributes();        
  }else{
      echo '<title>' . perch_pages_title(true) . '</title>';
      perch_page_attributes();
  }
?>

<-- how the check works -->

<?php
    perch_layout('header', array(
        'blog-post' => true
    ));
?>

<?php
  $post_slug = perch_get('s');
?>

On one its getting title and description from normal pages other getting from blog, however it is not doing it for blog. Is there something I done wrong? Whats the correct way? Whats the way forward

Luke Jennings

Luke Jennings 0 points

  • 3 years ago
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hi Luke,

Is all this code in one file?

The section at the top should be in a Layout templates/layouts/header.php:

<?php
if (perch_layout_has('blog-post')) {
perch_blog_post_meta(perch_get('s'));
perch_page_attributes(); 
}else{
echo '<title>' . perch_pages_title(true) . '</title>';
perch_page_attributes();
}
?>

This way when you use perch_layout('header') at the top of your page, the layout templates/layouts/header.php will be included in the page.

Hey, Hey the top section is in the header.php. the bottom section is in the post.php

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

What's in your templates/blog/meta_head.html?

And is the blog post otherwise being displayed?

Posts are being displayed however i dont have blog/meta_head.html since my templates are coming from foundation zurb.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Posts are being displayed however i dont have blog/meta_head.html since my templates are coming from foundation zurb.

You are free to use any framework you want. You still can use Perch templates.

You are using:

perch_blog_post_meta(perch_get('s'));

The above uses perch/templates/blog/meta_head.html by default.

You can find the default template in perch/addons/apps/perch_blog/templates/blog/meta_head.html.

These are the contents of the meta_head

<perch:blog 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" />"
<perch:blog id="og_description" label="Social description" type="textarea" size="s" escape="true" />
<perch:blog id="og_image" label="Image when shared" help="Should be at least 1200x630" type="image" width="1200" />
<perch:blog id="og_type" label="Facebook type" type="select" options="article,book,profile,website,video,music" allowempty="true" />
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

This looks like the default post_meta.html template which is used for editing.

The default meta_head.html template is:

<title><perch:blog id="postTitle" /></title>
<meta property="og:site_name" content="<perch:setting id="perch_blog_site_name" />" />
<meta property="og:url" content="<perch:blog id="domain" type="hidden" /><perch:blog id="postURL" type="hidden" />" />
<meta property="og:title" content="<perch:blog id="og_title" label="Social title" type="text" escape="true" />" />
<meta property="og:description" content="<perch:blog id="og_description" label="Social description" type="textarea" size="s" escape="true" />" /><!--* *-->
<perch:if exists="og_image">
<meta property="og:image" content="<perch:blog id="domain" type="hidden" /><perch:blog id="og_image" label="Image when shared" help="Should be at least 1200x630" type="image" width="1200" />" />
</perch:if><!--* *-->
<perch:if exists="og_type"><!--* *-->
<meta property="og:type" content="<perch:blog id="og_type" label="Facebook type" type="select" options="article,book,profile,website,video,music" allowempty="true" />" />
</perch:if><!--* *-->
<meta property="article:author" content="<perch:blog id="author_facebook" type="hidden" />" />

<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="<perch:blog id="author_twitter" type="hidden" />" />
<meta name="twitter:title" content="<perch:blog id="og_title" label="Social title" type="text" escape="true" />" />
<meta name="twitter:description" content="<perch:blog id="og_description" label="Social description" type="textarea" size="s" escape="true" />" /><!--* *-->
<perch:if exists="og_image">
<meta property="twitter:image" content="<perch:blog id="domain" type="hidden" /><perch:blog 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:blog id="domain" type="hidden" /><perch:blog id="postURL" type="hidden" />" />

Fixed, just had to put all code on the bot into the header php and it worked