I want to be able to add a meta tag from a view (or controller if possible) in CakePHP
I have a page like /mycontroller/myview
but when it is accessed with filters like:
/mycontroller/myview/page:2/max_price:500
Then I want to add meta no follow tags.
There is a meta method on the HtmlHelper class.
When I call it like this:
$this->Html->meta('keywords', 'test test test', array('inline'=>false));
It creates a meta tag like this:
<meta name="keywords" content="test test test" />
However, when I call it like this:
$this->Html->meta('robots', 'noindex, nofollow', array('inline'=>false));
I would naturally expect and want it to create this:
<meta name="robots" content="noindex, nofollow" />
Instead I get this though:
<link href="http://www.example.com/mycontroller/noindex, nofollow" type="application/rss+xml" rel="alternate" title="robots" />
What am I doing wrong?
From the documentation page (last line)
If you want to add a custom meta tag then the first parameter should be set to an array. To output a robots noindex tag use the following code:
echo $this->Html->meta(array('name' => 'robots', 'content' => 'noindex'));
In your case:
echo $this->Html->meta(array('name' => 'robots', 'content' => 'noindex, nofollow'),null,array('inline'=>false));
Hope this helps
Here's a tweaked version of the code from this page. I've tested it, and it does work:
<?php
echo $this->Html->meta(
array('name' => 'robots', 'content' => 'noindex, nofollow'),
null,
array('inline'=>false));
?>
Obviously you can write this in a single line -I just broke it down for ease of viewing here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With