# Kirby SEO - Serp preview field for the panel

**URL:** <https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605>\
**Category:** Plugins\
**Created:** [March 16, 2016, 1:57pm UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605 "2016-03-16T13:57:29Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![carstengrimm](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/carstengrimm/32/188_2.png) [@carstengrimm](https://forum.getkirby.com/u/carstengrimm)\
**Post date:** [December 3, 2016, 12:29am UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/61 "2016-12-03T00:29:06Z")

</div>

did not solve anything.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [December 3, 2016, 8:53am UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/62 "2016-12-03T08:53:23Z")

</div>

Would be helpful to have the error message you get for the highlighted line?

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [December 16, 2016, 3:19pm UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/63 "2016-12-16T15:19:54Z")

</div>

@texnixe @carstengrimm

I had the same problem when I updated to PHP 7.1 and set it to array works.

I’ve updated the repo: [https://github.com/jenstornell/kirby-seo/blob/master/seo.php](https://github.com/jenstornell/kirby-seo/blob/master/seo.php)

---

<div class="post-metadata">

**Author:** ![Thomasorus](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thomasorus/32/857_2.png) [@Thomasorus](https://forum.getkirby.com/u/Thomasorus)\
**Post date:** [February 4, 2017, 10:01pm UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/64 "2017-02-04T22:01:20Z")

</div>

Hi, i just finished my install and everything works except a visual thing.  
When previewing the search, if the title or text used as fallbacks contain one ’ or various ', the preview is not working.

For example with a title named "_Test’_ ", the plugin [returns this](http://i.imgur.com/QwHI4Br.jpg).  
Sorry for the screencap but for some reason part of the double quotes turn into this:

```
<div class="seo" data-seo-controller="{&quot;values&quot;:{&quot;sitename&quot;:&quot;blog name&quot;,&quot;pagename&quot;:&quot;Test" ","content":"hello"},"title":{"field":"","template":"{{pagename}}","prefix":"","suffix":"="" on="" blog="" name","backup":"{{pagename}}","fallback":"{{pagename}}","full":"{{pagename}}="" {{sitename}}","full-replaced":"test'="" name"},"description":{"field":"","template":"{{content}}","backup":"{{content}}","fallback":"{{content}}","full":"{{content}}","full-replaced":"hello","prefix":"","suffix":"","limit":155},"url":{"edit":"http:\="" \="" kirby.sites.dev\="" panel\="" pages\="" blog\="" test\="" url","preview":"kirby.sites.dev\="" test"}}'=""> 

```

Each ’ seems to be replaced by " which breaks the data-seo-controller attribute content. I don’t know what could create something like this so I need your help. I’m using Kirby 2.4.1.

---

<div class="post-metadata">

**Author:** ![carstengrimm](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/carstengrimm/32/188_2.png) [@carstengrimm](https://forum.getkirby.com/u/carstengrimm)\
**Post date:** [June 21, 2017, 2:35pm UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/65 "2017-06-21T14:35:13Z")

</div>

plugin broke with 2.5.0

```auto
Undefined index: scheme in file /plugins/seo/core/core.php on line 290

```

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [June 21, 2017, 2:53pm UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/66 "2017-06-21T14:53:48Z")

</div>

I bet it’s related to this issue: [https://github.com/getkirby/kirby/issues/588](https://github.com/getkirby/kirby/issues/588)

If `$page->url()` is not a full url, I guess it will fail.

> <https://github.com/jenstornell/kirby-seo/blob/master/core/core.php#L79>

> <https://github.com/jenstornell/kirby-seo/blob/master/core/core.php#L290>

---

<div class="post-metadata">

**Author:** ![carstengrimm](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/carstengrimm/32/188_2.png) [@carstengrimm](https://forum.getkirby.com/u/carstengrimm)\
**Post date:** [June 21, 2017, 2:59pm UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/67 "2017-06-21T14:59:14Z")

</div>

are you gonna fix it?  
we have stuck on 0.5 for so long and i implemented serp preview on a few projects and would be annoying to either revert everything or not being able to update.

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [June 22, 2017, 10:22am UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/68 "2017-06-22T10:22:39Z")

</div>

No. It’s not really an issue in the plugin, it was Kirby 2.5.0. Therefor a fix in the plugin would be a hack.

But you can now fix it by upgrading Kirby again or as a workaround [set the site url in config.php](https://getkirby.com/docs/cheatsheet/options/url).

> [@Bugfix-Release: 2.5.1](https://forum.getkirby.com/t/bugfix-release-2-5-1/7787):
>
> Yikes! I hate it, when this happens. A last minute bug made it into 2.5.0 and a couple of you already reported issues with broken URLs. I’m really sorry about this. Unfortunately none of our tests detected it frowning We decided to publish a fix for it as soon as possible and so here’s a very unglamorous bugfix release, which you should use instead of 2.5.0: [https://getkirby.com/changelog/kirby-2-5-1](https://getkirby.com/changelog/kirby-2-5-1)

Why there has been no update since 0.5 is because of this problem. I got tired of breaking my multi language site with Kirby SEO for an unknown reason.

> <https://github.com/getkirby-v2/panel/issues/943>
>
> https://forum.getkirby.com/t/panel-language-session-problem/4959
> 
> If a field c…ontains javascript it's a risk that they can make the panel save in the wrong language in a multi language setup. I think it's very serious because of the frustration that comes with lost/overwritten content.
> 
> This issue is not new, I just don't think it has been addressed before.
> 
> \*\*Fields that I know suffer from it:\*\*
> 
> https://github.com/jenstornell/kirby-seo
> https://github.com/jenstornell/kirby-boiler-plugin
> https://github.com/jenstornell/kirby-boiler-field
> 
> \## To reproduce
> 
> \### 1. Install Kirby multi languages
> 
> \*\*In the Kirby Cli:\*\*
> 
> \`\`\`
> kirby install bigbug --kit langkit
> \`\`\`
> 
> \### 2. Install boiler field or below
> 
> You can install the boiler field to try it, link above. If not here is an even simpler version of the boiler field:
> 
> \*\*It's a field, not a plugin. It's named \`boiler.php\`\*\*
> 
> \`\`\`php
> \<?php
> class BoilerField extends BaseField {
> static public $fieldname = 'boiler';
> static public $assets = array(
> 'js' =\> array(
> 'script.js',
> ),
> );
> 
> public function input() {
> $html = '\<input type="text" class="input" id="' . $this-\>id() . '" name="' . $this-\>name() . '" value="' . $this-\>value() . '"\>';
> return $html;
> }
> 
> public function element() {
> $element = parent::element();
> $element-\>data('field', self::$fieldname);
> return $element;
> }
> 
> public function routes() {
> return array(
> array(
> 'pattern' =\> 'ajax/(:any)/(:any)',
> 'method' =\> 'get',
> 'action' =\> function($var1, $var2) {
> return response::json( array( $var1, $var2 ) );
> }
> )
> );
> }
> }
> \`\`\`
> 
> \*\*script.js\*\*
> 
> \`\`\`js
> (function($) {
> $.fn.boiler = function() {
> return this.each(function() {
> var field = $(this);
> var fieldname = 'boiler';
> 
> if(field.data( fieldname )) {
> return true;
> } else {
> field.data( fieldname, true );
> }
> $.fn.ajax(fieldname);
> });
> };
> 
> $.fn.ajax = function(fieldname) {
> var blueprint\_key = $('\[data-field="' + fieldname + '"\]').find('\[name\]').attr('name');
> var base\_url = window.location.href.replace('/edit', '/field') + '/' + blueprint\_key + '/' + fieldname + '/ajax/';
> $.ajax({
> url: base\_url + '1/value',
> type: 'GET',
> success: function(result) {
> console.log('Hello from Ajax!');
> console.log(result);
> }
> });
> };
> })(jQuery);
> \`\`\`
> 
> \### 3. Add to your blueprint
> 
> \*\*default.yml\*\*
> 
> \`\`\`yml
> title: Bug
> fields:
> title:
> label: Title
> type: text
> boiler:
> label: Bug
> type: boiler
> \`\`\`
> 
> \### 4. Run it
> 
> In the test above, when I save in DE it switches back to EN.
> 
> !\[bigbug\](https://cloud.githubusercontent.com/assets/927011/19849380/37ab6e6a-9f53-11e6-80c9-fb6eccf16cb8.gif)
> 
> This issue in this particular case has to do with the ajax route, that it does not go to a language specific version of the panel and that makes it switch back to EN.
> 
> With my Kirby SEO it's still unknown why the same thing happends there.
> 
> \## In conclusion
> 
> For me this proves that the panel is quite fragile. A field can this easily break the save behavior. I want it to be solid as a rock.
> 
> \*\*Suggestions:\*\*
> 
> \- Keep \`en\` or whatever language prefix in the url to never accidently switch away from it.
> \- Same as above with a get variable.
> \- Keep it in a hidden field, not in memory.
> 
> That would mean that I can't switch language by accedent from an ajax route or anything else. I will no longer be worried that my content is lost when using multiple languages.

But I agree that a new version soon would be nice. The same goes for a few other of the plugins, like [Revisions](https://github.com/jenstornell/kirby-revisions), [Reveal](https://github.com/jenstornell/kirby-reveal) etc.

---

<div class="post-metadata">

**Author:** ![carstengrimm](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/carstengrimm/32/188_2.png) [@carstengrimm](https://forum.getkirby.com/u/carstengrimm)\
**Post date:** [June 22, 2017, 11:52am UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/69 "2017-06-22T11:52:05Z")

</div>

2.5.1 seems to work yes.

---

<div class="post-metadata">

**Author:** ![Thomasorus](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thomasorus/32/857_2.png) [@Thomasorus](https://forum.getkirby.com/u/Thomasorus)\
**Post date:** [July 26, 2017, 11:46am UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/70 "2017-07-26T11:46:47Z")

</div>

I had a bit of time to come back to my initial problem. Having ’ or " in the text and title broke the Json in data-seo-controller.

Dirty/rapid fix in core.php, getvalues function:

```
// Get values
public static function getValues($array, $arrays) {
	if( isset( $arrays ) ) {
		foreach( $arrays as $item ) {
			foreach( $item['values'] as $key => $value ) {
				//$array['values'][$key] = (string)$value; <- original code
				$array['values'][$key] = str_replace('&quot;', "\"", str_replace("'", "&#39;", (string)$value));
			}
		}
	}
	return $array;
}

```

Hope it helps, thanks for the great plugin @jenstornell.

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [July 27, 2017, 7:31pm UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/71 "2017-07-27T19:31:06Z")

</div>

Thanks! A new release for Kirby SEO is still not around the corner, sorry. But I have plans in the future for a complete rewrite and maybe your code could be useful at that point.

---

<div class="post-metadata">

**Author:** ![luxlogica](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/luxlogica/32/437_2.png) [@luxlogica](https://forum.getkirby.com/u/luxlogica)\
**Post date:** [October 9, 2017, 3:39am UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/72 "2017-10-09T03:39:37Z")

</div>

@Thomasorus There is a [pull request](https://github.com/jenstornell/kirby-seo/pull/47) that fixes this problem, already waiting to be incorporated into the code. The fix is very simple - less than one line - so if you can’t wait, you can just view it in GitHub, and copy it directly into your code.

@jenstornell This is one of my most favourite plugins for Kirby. I have noticed that some pull requests have been in the queue for a while, and this makes me concerned that you might have given up on further development. Please, please tell me that this is not true! 😢

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [October 9, 2017, 5:59am UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/73 "2017-10-09T05:59:13Z")

</div>

You are right, it has been a while. The reason I stopped working on it was because of a multi language Kirby bug. Maybe it has been fixed now, I have not tested it yet: [Really strange behavior that makes Kirby save to wrong content file](https://forum.getkirby.com/t/really-strange-behavior-that-makes-kirby-save-to-wrong-content-file/5786/13)

Now there is a development going in with Kirby 3. You can buy to get more information about that with [https://getkirby.com/next](https://getkirby.com/next)

I can’t tell you anything on what it will be, but the changes are so big that I need a complete rewrite of Kirby SEO, which I had already planned because of the ugly code. It might not be good news but instead of building two plugins from scratch I will wait until Kirby 3 is released and build the plugin from scratch to that version only.

If you still want some progress with the current version you can add pull requests and also write comments on each others pull requests if they work or not and I can just approve them.

Anyway, if I get the time, I should be able to start over with the new plugin before Kirby 3 but that will be to clean up the plugin core and nothing around the field itself.

I expect the new version to be released in the mid or late 2018.

---

<div class="post-metadata">

**Author:** ![luxlogica](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/luxlogica/32/437_2.png) [@luxlogica](https://forum.getkirby.com/u/luxlogica)\
**Post date:** [October 9, 2017, 8:35am UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/74 "2017-10-09T08:35:24Z")

</div>

Very happy to hear that Kirby SEO will continue to live a long and prosperous life, @jenstornell! Thank you for your continuing work - it’s truly appreciated.

The plugin, ‘as-is’ - coupled with a couple of the fixes already submitted - is already extremely useful, and helpful in making users understand how important ‘title’ and ‘description’ are - and how to compose better ones.

I’ll certainly keep using it, and if I come across anything that I can ‘fix’, I certainly will.

Once again, thank you for your great work - it’s truly appreciated!

---

<div class="post-metadata">

**Author:** ![luxlogica](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/luxlogica/32/437_2.png) [@luxlogica](https://forum.getkirby.com/u/luxlogica)\
**Post date:** [October 10, 2017, 1:20am UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/75 "2017-10-10T01:20:49Z")

</div>

When using this plugin, I find that the ‘Title’ field is often unnecessary in the Panel. Is there a way to totally _hide the Title field_ - rather than just make it ‘readonly’, but still showing?

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [October 10, 2017, 5:51am UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/76 "2017-10-10T05:51:53Z")

</div>

You mean the panel `title` field? You can just remove it from the blueprint. It’s no longer required.

[https://github.com/getkirby/kirby/issues/277](https://github.com/getkirby/kirby/issues/277)

---

<div class="post-metadata">

**Author:** ![Thomasorus](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thomasorus/32/857_2.png) [@Thomasorus](https://forum.getkirby.com/u/Thomasorus)\
**Post date:** [February 16, 2019, 7:24pm UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/77 "2019-02-16T19:24:44Z")

</div>

Sorry about reviving this topic @jenstornell!

I just wanted to post an update for the few people like me that are migrating out of this plugin. Here’s how I transformed my content files using regex commands. It’s just a small guide that may not completely work with your content so no garanties. Be sure to **make copies of your content folder!**

**Case 1: All fields are filled** :

```auto
----

Seo: 

-
  seo-title: "This is my SEO title"
  seo-description: "This is my SEO description"

----

```

**Case 2: Only title is filled** :

```auto
----

Seo: 

-
  seo-title: "This is my SEO title"
  seo-description: ""

----

```

**Case 3: Only description is filled** :

```auto
----

Seo: 

-
  seo-title: ""
  seo-description: "This is my SEO description"

----

```

**Case 4: There’s just the parent field** :

```auto
----

Seo: 

----

```

**Case 5: All fields exist but are empty** :

```auto
----

Seo: 

-
  seo-title: ""
  seo-description: ""

----

```

I’m not that good with regex so I did it in multiple steps. Here are the regex I used. You can see in the links the regex to select the text, the text itself and the replacement regex.

**For cases 1, 2, 3 and 5, I used these 3 steps in visual studio code** :

1. Removing the Seo block and renaming the title while also removing the double quote at the start of the title: [https://regexr.com/48gqt](https://regexr.com/48gqt)
2. Removing the double quote at the end of the title, separating and renaming seo-description, and removing the double quote again at the start of the description: [https://regexr.com/48gr0](https://regexr.com/48gr0)
3. Removing the last double quote at the end of the description. For this I checked what was the next field in my files and it was keywordmap, so I did this: [https://regexr.com/48gr3](https://regexr.com/48gr3)

**For cse 4, I used this single regex** :

1. Remove the block and just leave a separator line: [https://regexr.com/48gr6](https://regexr.com/48gr6)

For the snippet header, I just used a simple condition:

```auto
<title>
  <?php 
     if(!$page->seotitle()->isEmpty()) {
        echo $page->seotitle();
     }
     else {
       echo $page->Title();
     } 
   ?>
</title>

<meta name="description" content="
    <?php 
        if(!$page->seodescription()->isEmpty()) {
           echo $page->seodescription();
        }
        else 
        {
          echo $page->text()->excerpt($chars = 240, $strip = true, $rep = '…');
        }?>
">

```

And that’s it, hope it helps!

---

<div class="post-metadata">

**Author:** ![dennisb](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/dennisb/32/11676_2.png) [@dennisb](https://forum.getkirby.com/u/dennisb)\
**Post date:** [March 6, 2019, 6:52pm UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/78 "2019-03-06T18:52:55Z")

</div>

@jenstornell do you have any updates planned for Kirby SEO for v3 in the near future?

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [March 6, 2019, 7:38pm UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/79 "2019-03-06T19:38:27Z")

</div>

No sorry. I hope someone will take over.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 6, 2019, 7:56pm UTC](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605/80 "2019-03-06T19:56:06Z")

</div>

[https://forum.getkirby.com/t/seo-for-kirby-3/13228?u=texnixe](https://forum.getkirby.com/t/seo-for-kirby-3/13228)

[Previous page](https://forum.getkirby.com/t/kirby-seo-serp-preview-field-for-the-panel/3605.md?page=3)
