Thread tagged as: Meta, Runway, Blog

Title tag not displaying for blog posts


I've just about got all of the SEO meta info working except all of the blog post titles are still coming out as "Blog Post".

This is the snippet from my global.php layout:

    <title><?php perch_pages_title(); ?></title>
        if (perch_layout_var('meta', true)) {
            echo perch_layout_var('meta', true);
        } else {

which appears to be pulling the title in from the pages, but how do you override it for the blog? Ideally I would also like to customise the Category and Archive titles as well...but one step at a time.

Perch Runway: 2.8.5, PHP: 5.6.8, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $, with PDO
Server OS: Linux, cgi-fcgi
Installed apps: content (2.8.5), assets (2.8.5), categories (2.8.5), perch_blog (4.6), perch_mailchimp (2.0.1), collection_1 (2.8.5)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_blog', 'perch_mailchimp', );
PERCH_PATH: /var/sites/o/
PERCH_CORE: /var/sites/o/
PERCH_RESFILEPATH: /var/sites/o/
Image manipulation: GD
PHP limits: Max upload 100M, Max POST 100M, Memory: 128M, Total max file upload: 100M
Resource folder writeable: Yes
DOCUMENT_ROOT: /var/sites/w/
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Robin Waite

Robin Waite 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

For blog posts you don't want to use perch_pages_title() - that will be the same for each post. Use the post title instead

<title><?php perch_blog_post_field(perch_get('s'), 'postTitle'); ?></title>

Hi Drew,

Unfortunately the title is displayed in the global header layout, so if I change it to that then the title won't display on the normal pages. Do I have to create a different layout for the blog? Or can I put an if statement in to check whether it's a blog post or normal page?



Drew McLellan

Drew McLellan 2638 points
Perch Support

You can pass the title into the layout using a layout variable. If that variable is set, use it, else use the page title.

OK, I'm struggling with that somewhat. I've used layout variables to get the meta info but not sure how to change it to add the 'title' as a variable, here is what I've got working so far in post.php but it's not pulling through to the global.header:

    $post_slug = perch_get('year').'/'.perch_get('month').'/'.perch_get('s');
    $title = perch_blog_post_field(perch_get('s'), 'postTitle', true);
    perch_layout('global/header', array(
        'meta'  => perch_blog_custom(array(
                'template' => 'blog/meta.html',
                'filter' => 'postSlug',
                'match' => 'eq',
                'value' => $post_slug,
            ), true), 

and in my global.header:

<title><?php if (perch_layout_var('title', true)) { echo perch_layout_var('title', true); } else { perch_pages_title(); } ?></title>

Really appreciate your help, as this is the last major SEO bug I've got!

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, that looks fine - which part isn't working?

Hi Drew, it's still just outputting "Blog Post" when you're looking at a specific blog post. It's taking the title from the page which I've created rather than the layout variable. See

Drew McLellan

Drew McLellan 2638 points
Perch Support

Why not include the <title> tag in your meta.html template? That would save a database lookup.

Hi Drew, not sure why I didn't think of that in the first place. It works perfectly. Slightly confusing as there are now two title fields in the backend so a bit of house-keeping to tidy that up but it works brilliantly now. Many thanks for your help.