Custom meta tags for certain pages

Hello.
I would like to add the noindex meta tag to all the children of a specific page. How can I do this?

Is this correct?

<?php if($page->isChildOf(‘promotions’)): ?>
<meta name=“robots” content=“noindex nofollow” />

Second, should I do this? All children of this promotion page are time limited promotions. Is it a good idea to add the noindex meta for SEO purposes.

Thank you.

You should see if the meta tag is printed on the subpages or not if you inspect the page.

The if statement is correct, if promotions is a first level page, i.e. /content/promotions, but is missing an endif.

From a SEO perspective, I probably wouldn’t noindex, nofollow these pages, but rather redirect to the main product page once the promotion has ended. But then my SEO knowledge is limited.

Indeed I think it’s better to redirect to the main page or just replace the content with a text saying the promotion is not available anymore.
Thanks for the idea.

I think it would be better for SEO to simply list the promotions on that page rather then setting up pages for promotions (since this sounds like duplicate content) - do the promotions on the products full price page instead. That way you can have google index the promotions page and have that page link through to the full price page that has been temporarily changed with a special offer information.

As I understand it, the noindex, nofollow meta is guidance only - search engines should respect it but they don’t always do so. The links to those products on the promotions page should also have proper rel attributes on them too i think. You can also block those pages from search engines in your robots file.

Yes the promotion page lists all the active promotions. Usually max active promotions is 6. These are displayed as a thumb gallery. Every promotion has its own pages where more details are listed.
My first thought is that if I’m going to deactivate the page, the link will not be accessible. Which I just tested and proved it’s wrong. Links are still directly accessible. I thought it will just redirect to the error page which was my concern thinking it would affect SEO.

As commented above, I think redirect to the promotion page is the way to go.

If with deactivate you mean changing the status to invisible, then no, the page will still be accessible. Visible and invisible. are just flags you can filter by or use as a means to redirect.

For example, you can use a route that checks if the subpage of promotionsis visible or not. If visible, return the page; if invisible, redirect to the parent promotions page.

Yes I thought changing the status totally disables the page/link.

Honestly I haven’t dig these features yet. I’m newbie to PHP. Big thanks to this community though and the documentation, somehow I was able to put up a live website.
I will definitely read about this routes.

Update:
Started reading…:grinning: Maybe that’s why I stayed away from it…:grinning:

The route should look something like this (not tested):

c::set('routes', array(
  array(
    'pattern' => 'promotions/(:any)',
    'action'  => function($uid) {
        $page = page('promotions/'.$uid);
        if($page && $page->isVisible()) {
          return $page;
        elseif($page && $page->isInvisible()) {
          return go($page->parent()->uri(), 301);
        } else {
          go('error');
    }
  )
));

The pattern look for a child of the promotions page. Within the action, we check if the page exist. If it exists. and is visible, we give the user the page; if it is invisible, we redirect to the parent, if it doesn’t exist, show the error page.

Cool. I will test this on my local dev at home.
I’m guessing I don’t have to add anything on the promotion’s child template?

I’m not sure what’s wrong with the elseif line but it’s giving me a syntax error.

I think theres a missing closing Curly Bracket (or maybe two)… i can see 4 open brackets but only two closures.

Thanks. Indeed missing brackets.

This works for default language. How can I make it so it works on multi language setup?

Should be something like this:

c::set('routes', array(
  array(
    'pattern' =>[ 'promotions/(:any)', 'fr/promotions/(:any)', 'es/promotions/(:any)'],
    'action'  => function($uid) {
        $page = page('promotions/'.$uid);
        if($page && $page->isVisible()) {
          return site()->visit($page);
        elseif($page && $page->isInvisible()) {
          return site()->visit($page->parent()->uri());
        } else {
            return site()->visit('error');
    }
  )
));

It’s giving me error on this line.

Too few arguments to function Kirby::{closure}(), 0 passed in ...

Here’s what I have

c::set('routes', array(
  array(
    'pattern' =>[ 'promotions/(:any)', 'en/promotions', 'ar/promotions' ],
    'action'  => function($uid) {
        $page = page('promotions/'.$uid);

        if($page && $page->isVisible()) {
          return site()->visit($page);
        } elseif($page && $page->isInvisible()) {
          return site()->visit($page->parent()->uri());
        } else {
          return site()->visit('error');
        }
      }
  )
));

Sorry, I forgot to add the placeholders for the subpage for the languages, corrected above.

1 Like

Deleted my previous comment.
Still it doesn’t redirect to the correct current language. Noticed that the URL doesn’t change as well after it is redirected to its parent page.

Then try this, with these multi-language routes I’m never quite sure what works or not:

c::set('routes', array(
  array(
    'pattern' =>[ 'promotions/(:any)', 'en/promotions/(:any)', 'ar/promotions/(:any)'],
    'action'  => function($uid) {
        $page = page('promotions/'.$uid);
        if($page && $page->isVisible()) {
          return site()->visit($page);
        elseif($page && $page->isInvisible()) {
          return go($page->parent()->uri(), 301);
        } else {
            return go('error');
    }
  )
));