Get ID of the post when using ‘the_seo_framework_rel_canonical_output’
-
Hey,
I have seen many implementation of this filter “the_seo_framework_rel_canonical_output”
I need the post ID of the page in order to change the canonical link which I am unable to get.
I could try “url_to_postid()” function but the problem is that I have changed the permalink of my website using a plugin which makes the link of my product pages link.example.com/category/product-slug
So I am unable to get ID from there. A little bit of digging I found,
/** * @since 2.6.5 * @param string $url The canonical URL. Must be escaped. * @param int $id The current page or term ID. */ $url = (string) \apply_filters_ref_array( 'the_seo_framework_rel_canonical_output', [ $_url, $this->get_the_real_ID(), ] );
I can see the URL being pased to the filter, but when I try to get it like this.
add_filter( 'the_seo_framework_rel_canonical_output', function( $url , $id ) { var_dump($url, $id); return $url; } );
I get the following error
Too few arguments to function App\{closure}(), 1 passed in C:\laragon\www\cfi\wp-includes\class-wp-hook.php on line 289 and exactly 2 expected
How can I get the ID of product here ?
Thanks.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Get ID of the post when using ‘the_seo_framework_rel_canonical_output’’ is closed to new replies.