• Resolved pingbara

    (@pingbara)


    Normally, every page in my site will be automatically set the canonical url to be each page itself. But with the attachment page it is not, the canonical url of the attachment page is the url of the image file.

    1. How to set the canonical url of the attachment page to be the attachment page url itelf by without having to go through each media file to manually to input the canonical URL of the attachment page. I have around 3,700 attachemnt pages to do. Doing manually is impossible.

    2. Even the current existing canonical url is pointing to the image file, how come the attachemnt pages still rank in google. As far as i understand, if the canonical url is pointing to different page, then the page with canonical pointing out should not be indexed in google search result

    Thanks
    Methee

    • This topic was modified 3 years, 10 months ago by pingbara.

    The page I need help with: [log in to see the link]

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support Michael Ti?a

    (@mikes41720)

    Hi @pingbara

    By default, the canonical URL should automatically self-canonicalize and the Yoast SEO plugin should handle mostly everything without you needing to make any further changes — https://yoast.com/help/canonical-urls-in-wordpress-seo/

    1. If you set the ‘redirect attachment page to attachment itself’ toggle to ‘yes’, then the attachment page should have a 301 redirect to the attachment itself, so we’re not sure if the canonical URL would still matter here.

    2. It’s possible that even if you’ve set the canonical URL to something else, that that page would still appear in the search results, especially if it was already previously indexed. However, you’re correct that if you set the canonical to another URL, it is signaling to Google that you want that version of the page to be the one that should be in the search results. You can learn more about it here – https://yoast.com/rel-canonical/

    Thread Starter pingbara

    (@pingbara)

    The problem is that i DID NOT set the redirect attachment page to attachment itself to ‘yes’.
    But the canonical url is not self-canonicalize. Instead, its canonical url point to “the image file”.

    You can check the url above that i have provided.

    Thread Starter pingbara

    (@pingbara)

    @suwash kunwar

    No, you cannot use the “site: followed by url+slug” for the non English url.
    I can confirm that this URL is indexed and ranked in google, please see below snapshot:

    https://drive.google.com/file/d/1-G8Q1QO3ypQGfScRqw-1DVwHIyhP_EEQ/view?usp=sharing

    Anyway, this is not the main problem. My main problem is that “why my attachment page is not automatically self-canonicalize ?” Please see below screenshot for more information:

    https://drive.google.com/file/d/1AyG3dHyQYPCfH6E3aMHqBlzpRh-luM7S/view?usp=sharing

    Thanks
    Methee S.

    • This reply was modified 3 years, 10 months ago by pingbara.
    Plugin Support Michael Ti?a

    (@mikes41720)

    Hi @pingbara

    Upon checking this in a test site, we can confirm that setting the ‘redirect attachment URL to the attachment itself’ option to ‘no’ and the option of ‘yes’ to have media show in the search results, and then checking on one of the attachment pages, we do see that the canonical URL is indeed referencing the actual file path and not the attachment page itself.

    We’ll have to check with our developers further if this is the expected outcome and best practice, as we normally just do advise that you set the ‘redirect attachment URL to the attachment itself’ option to ‘yes’ so that the thin content pages are redirected to the image itself.

    Just to clarify, do you want the canonical URL to be the attachment page itself so that it shows up in the search results? You can modify the output of the canonical URL by checking out the developer filter here — https://yoast.com/help/canonical-urls-in-wordpress-seo/

    Thread Starter pingbara

    (@pingbara)

    Yes, correct I want the conaical url of the attachment page to be the attachment page itself. I think many types of businsess such as photography, the attachement pages are very important if modified correctly.

    I have taken a look in your recommended developr filter, I can’t find the code to fix my question. I don’t think I can do the filter for my problem. It is so difficult for me. I don’t know much about coding I know only some basic html and css that is why i rely on wordpress to build my sites.

    • This reply was modified 3 years, 10 months ago by pingbara.
    • This reply was modified 3 years, 10 months ago by pingbara.
    Plugin Support Md Mazedul Islam Khan

    (@mazedulislamkhan)

    Thanks for your clarification @pingbara. In most cases, the media (attachment) pages are useless for everyone and cause the thin content issue in the search results. So, Yoast SEO outputs the canonical URL pointing to the image file rather than the media (attachment) page.

    However, when it comes to the photography-based website where you are optimizing the media (attachment) pages with content and media files together, we can see why you need the canonical URL pointing to the media (attachment) pages themselves.

    That said, you can customize the canonical URL that’s outputting by the Yoast SEO plugin using the wpseo_canonical filter. A relevant example code snippet is given here: https://developer.yoast.com/features/seo-tags/canonical-urls/api/#change-the-canonical-url

    We understand that you’re not familiar with PHP code customization. In this case, we have provided the following code snippet for you that will output the current page URL on the media (attachment) canonical instead of the image file. You’ll need to add the relevant code to the end of your currently active theme’s functions.php file before the closing PHP ?> tag.

    function disable_canonical_on_media_attachment( $canonical ) {
    	if ( is_attachment() ) {
    		global $wp;
    		$wp->parse_request();
    
    		$canonical = home_url( $wp->request );
    	}
    
    
    	return $canonical;
    }
    
    add_filter( 'wpseo_canonical', 'disable_canonical_on_media_attachment' );
    

    For your site’s health and safety, we recommend creating regular backups of your site and database. This is especially important before editing files on your website. Learn more about the benefits of regular backups.

    Note: if you need further assistance on customizing the provided code snippet, you’ll need to find someone who is more familiar with PHP code customization as providing assistance on custom code goes beyond the scope of our support.

    Plugin Support Md Mazedul Islam Khan

    (@mazedulislamkhan)

    @pingbara we’d also like to mention that we have already created a bug report internally so that our SEO and development team both can decide and change the current behavior if needed.

    Thread Starter pingbara

    (@pingbara)

    @mazedulislamkhan

    Thanks for your help. I will try adding the php code.

    Best Regards
    Methee

    Plugin Support Michael Ti?a

    (@mikes41720)

    Hi,

    Since we’ve already logged this issue internally, and have provided a developer filter in order to modify the canonical URL output to be the attachment page URL itself, we will be setting this to resolved.

    Please do check the changelog or future releases of the Yoast SEO plugin from time to time for updates, enhancements, and bug fixes.

    Thanks!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Canonical URL of the attachment pages are not the URL of attachment pages.’ is closed to new replies.