BSG21
Forum Replies Created
Viewing 6 replies - 1 through 6 (of 6 total)
-
Thanks for that. Just wanted to make sure. Been doing a lot of auditing lately and that jumped out at me.
Duplicate
Awesome, that works perfectly. Thank you!
Forum: Fixing WordPress
In reply to: Getting Parent Post Outside of LoopThis code will do it:
global $wp_query; $attachment_page_id = $wp_query->post->ID; $parent_post = get_post($attachment_page_id); $parent_post_id = $parent_post->post_parent; $parent_post_permalink = get_permalink($parent_post_id);Alright, I got it to work but it is outputting the canonical <link > tag twice.
This is the code I used I just need to know what extra step(s) I need to take to keep it from duplicating
function attachment_wpseo_canonical ($can) { global $wp_query; $attachment_page_id = $wp_query->post->ID; $parent_post = get_post($attachment_page_id); $parent_post_id = $parent_post->post_parent; $parent_post_permalink = get_permalink($parent_post_id); echo "<link rel=\"canonical\" href=\"$parent_post_permalink\" />"; } add_filter('wpseo_canonical','attachment_wpseo_canonical');Thanks for the response. How do I get the post url that the attachment is assigned to outside the loop since I will need to do this before the loop.
Viewing 6 replies - 1 through 6 (of 6 total)