Skip to content

Commit

Permalink
Try out clickbaity titles for the details page
Browse files Browse the repository at this point in the history
I don't like it, but my site can't do any good when it can't be found on Google, and it isn't pushed on Google when nobody clicks on it.

#3
  • Loading branch information
cristan committed Feb 11, 2025
1 parent 0a2ab66 commit 4d4fdb7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions details/detailsLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ public static function vincentyGreatCircleDistance($latitudeFrom, $longitudeFrom
return $angle * $earthRadius;
}

private function isSearchEngineBot() {
return preg_match('/googlebot|bingbot|slurp|duckduckbot|baiduspider|yandexbot|sogou|exabot/i', $_SERVER['HTTP_USER_AGENT']);
}

private function enrich($country, $location, $connection, $locationFromDb)
{
$name = $locationFromDb['name'];
Expand All @@ -140,11 +144,19 @@ private function enrich($country, $location, $connection, $locationFromDb)

$toReturn = new stdClass();
$unlocode = $country.$location;
if ($subdivision) {

if ($this->isSearchEngineBot()) {
$toReturn->title = "UN/LOCODE {$unlocode}: Its location, region, coordinates and more";
} else if ($subdivision) {
$toReturn->title = "{$unlocode}: {$name} - {$subdivision} - {$countryName} | UN/LOCODE info";
} else {
$toReturn->title = "{$unlocode}: {$name} - {$countryName} | UN/LOCODE info";
}
$toReturn->description = "Need to identify the UN/LOCODE {$unlocode}? Discover its location here.";

if ($subdivision) {
$toReturn->header = "<a href='/country/{$country}'>{$country}</a>{$location}: {$name} - {$subdivision}";
} else {
$toReturn->title = "{$unlocode}: {$name} - {$countryName}";
$toReturn->header = "<a href='/country/{$country}'>{$country}</a>{$location}: {$name}";
}

Expand All @@ -165,7 +177,6 @@ private function enrich($country, $location, $connection, $locationFromDb)
$toReturn->regionType = $region['type'] ?? 'Region';
$toReturn->regionName = $region['name'] ?? null;
}
$toReturn->description = "Details for UNLOCODE {$unlocode}: {$name} in ".($toReturn->regionName ?? $subdivision).", {$toReturn->country}. Discover functions, coordinates and more.";

// Coordinates
$coordinates = $locationFromDb['coordinates'];
Expand Down
2 changes: 1 addition & 1 deletion home/sitemapinclude.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
// lastmod format is YYYY-MM-DD
$homeLastMod = '2025-02-03';
$countryLastMod = '2025-02-03';
$unlocodeLastMod = '2025-02-03';
$unlocodeLastMod = '2025-02-11';

$numResultsPerSitemap = 1000;

0 comments on commit 4d4fdb7

Please sign in to comment.