Recent Topics

1 Mar 18, 2014 07:07    

This comment has been moved from the Online manual (http://b2evolution.net/man/back-office-reference/managing-content/editing-items/post-advanced-properties-fieldset#c101086)

@cipher0 wrote:

What file controls these advanced properties? If it's possible, I'd like to change one of the meta tags to a link tag so I can add a canonical link to a post.

2 Mar 18, 2014 08:03

Here is a work around that may help you.

1. Go to the file /blogs/inc/skins/_skin.funcs.php and look for the function skin_description_tag.
2. Find this instruction: $r = $Item->get_metadesc();, it should be around the line 930.
3. Paste this code right below the mentioned instruction:


		// Adding cannonical links to the post by including them at the metadesc field with the following syntax: [[http://myexample.com]]
		// This hack will only add the first url found in that field.
		if( !empty( $r ) && preg_match_all( '/\[\[(.*?)\]\]/i', $r, $matches ) )
		{  // Cannonical link url included in the metadesc field
			echo '<link rel="canonical" href="'. $matches[1][0] ."\" />\n";
			
			$r = preg_replace( '/\[\[(.*?)\]\]/i', '', $r );
		}

Now, you can type the canonical url in the field <meta> desc:. Remember to wrap it by two open and close square brackets, like this: [[http://example.com]]. The following tag will be included into the <head> section of the html code at your post:


<link rel="canonical" href="http://example.com/" />

Regards!

4 Mar 21, 2014 07:57

Wow, brother! You are something else!

Although I haven't implemented your solution yet, it seems to be just what I've been looking for. I have content on non-b2evolution sites that I would like to post on b2evolution, so 301 isn't really something I can use. This canonical solution should do the trick!

Thanks, man, you are awesome!

[Sorry for asking a question on the manual page, I thought that was what the comment section was for. I know better now.]

5 Mar 21, 2014 10:31

Don't worry @cipher0, your post was fine there in the manual page, but here we could have a more organized discussion, specially knowing that I was about to share some code.

Actually, b2evolution manages both, canonical links and 301 redirect, automatically when it detects that the URL of the post is not as it's supposed to be. But, in the situation you described, having external pages, it looks like you need to specifically push that custom <link> tags into each post page, so the hack will do the work for you. Just remember that you should manually maintain all the links you have added to your posts.

Regards!


Form is loading...