The ModMy sites run on vBulletin, and we use vBSEO for our SEO tool. Beginning in vBulletin 4.+, vBulletin has had a built in CMS called vBCMS for posting articles. Before that most people used vBAdvanced or WordPress for vBulletin 3.x installs.

After moving to vBCMS for our articles, we discovered we could no longer get social sharing buttons (like Facebook, Twitter, Google Plus, Digg, etc) to work on the front page. Because we use vBSEO (which rewrites URLs server-side through PHP) and the button codes are all in JavaScript (which is client-side), attempting to use vBulletin’s standard {vb:raw page_url} was returning the standard vBulletin URL, not the correct vBSEO’d URL. I asked for help at multiple times, but they simply told me they don’t support vBCMS (great – that’s ALL our articles). I finally found a solution which I thought I’d share here as I’m sure others are looking for it. So here’s what I did to fix this.

I created a plugin and called it vbseod url.

The product was vBulletin, hook location is vbcms_article_populate_end. Execution order I set at 5. The following was the plugin code that eventually worked:

$replace_forvbseo = array('','','content.php?r=','.');
$replace_withvbseo= array('','','','-');

$replace_forvbseo2 = array('-that-','-was-','-as-','-of-','-in-','-is-','-it-','-an-','-and-','-with-','-for-','-to-','-this-','-from-','-by-','-a-','-on-','-the-','-at-','-be-','-or-','(',')','*','–');
$replace_withvbseo2 = array('-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','','','','');

$view->page_url_vbseo = str_replace($replace_forvbseo2,$replace_withvbseo2,strtolower($vbulletin->options['bburl'] . '/content' . (str_replace($replace_forvbseo,$replace_withvbseo,($view->page_url))) . '.html'));

This creates a variable you can use in vBCMS called page_url_vbseo. You can of course set that to whatever you’d like, that’s just what I used. You’ll also need to change where I have and to your domain.

For some reason simply using the $replace_withvbseo wasn’t working for CMS articles, so I had to add in some manual stuff. I think I have the majority of them replaced (see $replace_forvbseo2 where I have listed the words I’ve found which still needed to be removed). If you need to add to those, you’ll have to add them in that line.

Then I had a nice variable working which I could put in my templates anywhere by adding {vb:raw page_url_vbseo}.

For instance, in my site, I decided to put Twitter, Facebook, and Google Plus on the homepage as options, so used this code:

<div id="share" style="margin: 3px 0 3px 0;"><a class="twitter-share-button" href="" data-text="Nice article -" data-url="{vb:raw page_url_vbseo}" data-count="horizontal" data-via="modmyi">Tweet</a><script type="text/javascript" src=""></script><script type="text/javascript">// <![CDATA[
      (function() {     var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;     po.src = '';     var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);   })();
// ]]></script>
<script type="text/javascript">// <![CDATA[
    (function(d){   var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}   js = d.createElement('script'); = id; js.async = true;   js.src = "//";   d.getElementsByTagName('head')[0].appendChild(js); }(document));
// ]]></script></div>

That may change as each platform adjusts their button codes, but it’s just the individual button codes (Google any buttons you’d like to get their code). Notice in there where I have put the {vb:raw page_url_vbseo} code. The correct vBulletin template to make these changes in is vbcms_content_article_preview. To have the buttons appear under the main title of each article like we do on, insert the share code I just pasted under the following code in the  vbcms_content_article_preview template:

<vb:if condition="$showtitle">
	<div class="title">
		<h3 class="article_preview">
			<a style="color: black;" href="{vb:raw page_url}"><span>{vb:raw title}</span></a> 
		<vb:if condition="$can_edit">
			<a class="edit" href="{vb:raw edit_url}">
			<img class="editimage" src="{vb:stylevar imgdir_cms}/edit_small.png" alt="{vb:rawphrase edit}" />

Make sure when you get your button code you tell it NOT to use the URL it’s on, but a custom URL. Then replace it with the above bold code, and that’s how I got the correct code from the large block above.

There you have it!

About Kyle Matthews

Kyle Matthews is an internet entrepreneur, musician, and amateur photographer. He lives in Tampa, FL (but hails from Seattle, WA) with his wife and son.