Skip to main content
added 154 characters in body
Source Link
andiOak
  • 171
  • 6

Continuing the first answer, from Pieter Goosen:

Using same code but without the current category/tag/taxonomy being repeated with a string of the same taxonomy, you can do this:

<?php
    global $wp;
    $current_url = home_url( $wp->request ) . '/'; // last part adds the "/" at the end
?>

Then for the canonical meta (or any other permalink placement):

<link rel="canonical" href="<?php echo $current_url ?>" />

Observe, this will fail for url:s that have query strings at the end and is only for "pretty urls", like domain.com/category/sub-category/.

Continuing the first answer, from Pieter Goosen:

Using same code but without the current category/tag/taxonomy being repeated with a string of the same taxonomy, you can do this:

<?php
    global $wp;
    $current_url = home_url( $wp->request ) . '/'; // last part adds the "/" at the end
?>

Then for the canonical meta (or any other permalink placement):

<link rel="canonical" href="<?php echo $current_url ?>" />

Continuing the first answer, from Pieter Goosen:

Using same code but without the current category/tag/taxonomy being repeated with a string of the same taxonomy, you can do this:

<?php
    global $wp;
    $current_url = home_url( $wp->request ) . '/'; // last part adds the "/" at the end
?>

Then for the canonical meta (or any other permalink placement):

<link rel="canonical" href="<?php echo $current_url ?>" />

Observe, this will fail for url:s that have query strings at the end and is only for "pretty urls", like domain.com/category/sub-category/.

Source Link
andiOak
  • 171
  • 6

Continuing the first answer, from Pieter Goosen:

Using same code but without the current category/tag/taxonomy being repeated with a string of the same taxonomy, you can do this:

<?php
    global $wp;
    $current_url = home_url( $wp->request ) . '/'; // last part adds the "/" at the end
?>

Then for the canonical meta (or any other permalink placement):

<link rel="canonical" href="<?php echo $current_url ?>" />