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

*

MB Themes

Re: Help me solve the problem, I have two canonical tags being generated.
« Reply #1 on: December 30, 2023, 09:08:11 PM »
Well you shoukd find out how it is generated and where.
Then you can correct code.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

MB Themes

Re: Help me solve the problem, I have two canonical tags being generated.
« Reply #2 on: December 30, 2023, 09:08:36 PM »
Or update canonical url function to always remove last slash.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

Re: Help me solve the problem, I have two canonical tags being generated.
« Reply #3 on: December 31, 2023, 09:46:16 PM »
Or update canonical url function to always remove last slash.

Please tell me how to do this?

*

MB Themes

Re: Help me solve the problem, I have two canonical tags being generated.
« Reply #4 on: January 04, 2024, 09:48:14 PM »
Add this to your functions:
Code: [Select]
// 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');
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

Re: Help me solve the problem, I have two canonical tags being generated.
« Reply #5 on: January 06, 2024, 03:46:54 PM »
Add this to your functions:
Code: [Select]
// 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 "/"

Re: Help me solve the problem, I have two canonical tags being generated.
« Reply #6 on: January 06, 2024, 05:57:33 PM »
Please tell me, using GPT chat I was able to solve the problem, will this be the right solution?

i changed this code
Code: [Select]
// 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
Code: [Select]
// 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);
« Last Edit: January 06, 2024, 06:03:23 PM by Дима Пупкин »

*

MB Themes

Re: Help me solve the problem, I have two canonical tags being generated.
« Reply #7 on: January 08, 2024, 01:14:35 PM »
Looks to have same effect  ;)
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots