e_url.php [part n.2]

building SEF-URL system for content plugin - 2. part
on Monday 16 July 2018
comments: 0

3. To solve how value of SEF-URL will be managed (generated, new field etc)

I decided to use generated field to avoid changing table structure. There is option to use custom field but I am not familiar with this part of content plugin, so the easiest way is probably the best.

To get sef-url: (I used the field 'content_sef' in e_url.php, so this determine key name)

$row['content_sef'] = eHelper::title2sef($row['content_heading'],'dashl');

Where to use it? Most of code is generated in old shortcodes, so I just add it to shortcodes that uses $row as global variable and return url in any format. If there are other places, I will find them during replacing url creation new way.

This way data are prepared for using SEF-URL.

4. To solve problem of double content (in case that both version are working together)

I am not able to replace all urls at once, so there will be old urls together with new ones. To avoid problem with double content I decided to use old urls as canonical.

Simple solution:
if(defined("e_URL_LEGACY")) {

   if (strpos(e_URL_LEGACY, 'content.php') !== false)     {
    define("e_PAGE", 'content.php');
   elseif (strpos(e_URL_LEGACY, 'content_manager.php') !== false)     {
     define("e_PAGE", 'content_manager.php');
	 if (substr(e_PAGE, 0, 7) == 'content')  {
	   $contentcanonicalurl = SITEURL.e_URL_LEGACY;
	   $debugtext = "Canonical URL from content plugin:  " . $contentcanonicalurl . "<br>";


I use JM Canonical plugin, so I can use it's debug mode:


But what if I want to use SEF-URL as canonical or use custom urls in future with JM Canonical plugin?

this works only with JM Canonical plugin:

Good question: Let this be managed by JM Canonical plugin or let JMC to ignore everything on content pages?

At least for manual canonical urls:

if (substr(e_PAGE, 0, 7) == 'content')  {
	   $canonicalurl = '';
	   $request_url = $tp->toDB(e_REQUEST_URL);
	   if($sql->retrieve('canonical_request_urls', 'canonical_id', "WHERE canru_url = '" . $request_url . "' LIMIT 1", true, true)) {
			// do nothing, JM Canonical plugin does rest
		 else { 
	   		$canonicalurl = SITEURL.e_URL_LEGACY;
	   $debugtext = "Canonical URL from content plugin:  " . $canonicalurl . "<br>";

Related urls will use legacy urls for now.


Other links

Follow us