Support Forums - Classified Ads Script Osclass
General osclass questions => Report bug => Topic started by: Дима Пупкин on December 29, 2023, 05:46:31 PM
-
Help me solve the problem, I have two canonical tags being generated.
/dom-i-sad
/dom-i-sad/
How can I make sure that on a page with slashes "/" the conanical address is without the slash /dom-i-sad
-
Well you shoukd find out how it is generated and where.
Then you can correct code.
-
Or update canonical url function to always remove last slash.
-
Or update canonical url function to always remove last slash.
Please tell me how to do this?
-
Add this to your functions:
// Enhance canonical URLs
function osc_enhance_canonical_url($url) {
if($url != osc_base_url() && $url != osc_base_url(false, true) && osc_rewrite_enabled()) {
if(substr($url, -1) == '/') {
$url = substr($url, 0, strlen($url)-1);
}
}
return $url;
}
osc_add_filter('canonical_url', 'osc_enhance_canonical_url');
osc_add_filter('canonical_url_osc', 'osc_enhance_canonical_url');
osc_add_filter('canonical_url_search', 'osc_enhance_canonical_url');
osc_add_filter('canonical_url_public_profile', 'osc_enhance_canonical_url');
-
Add this to your functions:
// Enhance canonical URLs
function osc_enhance_canonical_url($url) {
if($url != osc_base_url() && $url != osc_base_url(false, true) && osc_rewrite_enabled()) {
if(substr($url, -1) == '/') {
$url = substr($url, 0, strlen($url)-1);
}
}
return $url;
}
osc_add_filter('canonical_url', 'osc_enhance_canonical_url');
osc_add_filter('canonical_url_osc', 'osc_enhance_canonical_url');
osc_add_filter('canonical_url_search', 'osc_enhance_canonical_url');
osc_add_filter('canonical_url_public_profile', 'osc_enhance_canonical_url');
unfortunately this method did not help me, I added this code to functions.php but still two conanic tags are generated with and without "/"
-
Please tell me, using GPT chat I was able to solve the problem, will this be the right solution?
i changed this code
// Generate canonical URL on all pages
function osc_generate_canonical() {
if(osc_always_generate_canonical_enabled()) {
View::newInstance()->_exportVariableToView('canonical', osc_get_current_url());
}
}
osc_add_hook('init', 'osc_generate_canonical', 1);
on which the GPT chat was created
// Generate canonical URL on all pages
function osc_generate_canonical() {
if (osc_always_generate_canonical_enabled()) {
$currentUrl = osc_get_current_url();
// Remove trailing slash if it exists
$currentUrl = rtrim($currentUrl, '/');
View::newInstance()->_exportVariableToView('canonical', $currentUrl);
}
}
osc_add_hook('init', 'osc_generate_canonical', 1);
-
Looks to have same effect ;)