• Resolved Lrrr

    (@lrrr)


    Hello, I tested the plugin on a child theme and a block editor. It worked fine until I decided to uninstall it (I tested its options – I liked it). After uninstalling the plugin, all featured images on attachment pages stopped showing. Before installing plugin attachment pages works well. It only happens within the child theme. As soon as I use the parent theme, everything is ok. I downloaded the plugin as a standalone and had its code reviewed by AI. It didn’t find anything that would help. So after uninstalling the plugin, you need to add a code to the function.php file that returns the object id, if we are on the attachment page.

    add_filter( 'get_post_metadata', function( $value, $object_id, $meta_key, $single ) {
    // Check if WordPress is requesting the featured image (_thumbnail_id) for an attachment type
    if ( '_thumbnail_id' === $meta_key && 'attachment' === get_post_type( $object_id ) ) {
    return $object_id; // Return the attachment's own ID as its featured image
    }
    return $value;
    }, 10, 4 );

    The strange thing is that restoring the system files from a backup including the database didn’t help either(not sure if backup not affected yet). Maybe its something changed in JSON? This code is currently the only solution to display images on attachment pages after uninstalling the plugin. (For sure, I deleted all content from child function.php and it did not help either. )

    • This topic was modified 6 months, 3 weeks ago by Lrrr. Reason: additional info
    • This topic was modified 6 months, 3 weeks ago by Lrrr. Reason: corrected
    • This topic was modified 6 months, 3 weeks ago by Lrrr. Reason: clearing
    • This topic was modified 6 months, 3 weeks ago by Lrrr. Reason: correct meaning in title, template>attachmnet
    • This topic was modified 6 months, 3 weeks ago by Lrrr. Reason: Added info
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Jan-Willem

    (@janwoostendorp)

    Hi,

    Sorry to hear you’re having problems.
    You are using the native WordPress attachment pages right?
    What is the parent theme you are using?
    I’ve never seen anybody use that before, so there might be a bug that nobody ever encountered before.

    WordPress might do something of a fallback to the image itself as it’s featured image.
    But it might be a thing your theme does.

    If you can answer my questions I’ll investigate on Wednesday.
    Thanks!

    Jan-Willem

    Thread Starter Lrrr

    (@lrrr)

    Hi, (I tested it on the official twenty twenty five template and its child.) thanks to your answer, I tried something else, delete attachment.html in the child theme folder and finally delete the custom template for attachment in guttenberg. So when the child theme loads the attachment by default, everything works. However, as soon as I create a default copy of single.html as an attachment, and it doesn’t matter if it’s only in Guttenberg as a custom or some html file in the template folder, the image simply won’t load without the code and the space is empty. I tried both the feature image block and the content block. After this test, I’m not sure if the fact that I connected this behavior with your plugin is a combination of circumstances – that things changed at the time the plugin was uninstalled, or if it’s the behavior of wordpress. Anyway, I didn’t need the code before the plugin. On the other hand, I also tried to completely delete function.php in the child template and also without result, so the child theme is not the cause. But it doesn’t hurt in the parent template either. So it’s really weird.

    Only parent theme – ok
    child theme – ok
    child theme with custom attachment page – need fix (code above)

    After todays tests Im not sure, if your plugin is the cause. So, my apologize if not.

    Plugin Author Jan-Willem

    (@janwoostendorp)

    Hi,

    I tried a couple of things. On a freshly installed WordPress (6.7), with TwentyTwentyFive.
    Without the DFI plugin, of any other plugins.
    I uploaded a bunch of animal pictures.
    On attachment page I only see the animal image.

    Install DFI, and set a QuestionMark image as the DFI.
    On the attachment page there is only the animal image.
    This makes sense, as attachments as a post-type do not support thumbnails, see post_type_supports().

    When I add thumbnail support for attachments I only see the QuestionMarkDFI and the animal below.
    So my plugin works as intended.

    When I add your code snippet, I see the animal twice.

    On WordPress 6.9 The attachment pages don’t work at all.
    They immediately redirect to the image.jpg url.

    You describe other behavior, I guess that’s due to other plugins/custom functions.php.
    But I see no issue due to the DFI plugin.

    How this clarifies it more.

    Thread Starter Lrrr

    (@lrrr)

    Hi, thank you for try, but did you try make and use a child theme? I understand it as you did not. – Yes, you see the picture twice in that scenairo you described. Thats normal. The “fix” code is needed only for child theme. If you would be so kind to try it as I decribed, I would appreciate it. I did try almost everything (including disbaled all plugins). Thank you. Also, its concerning WP 6.9. You must manually allow the attachment pages if you are on fresh install. Attachment pages are disabled on fresh wp installs, but on already existing(only updated to 6.9+), they are normally available. Maybe it is due to this, as far as I understand WP is using featured image as content on attachmnets for wp 6.9 (but not sure)… And generally, yes, attachment pages are very useful, if you need content around your image. There are plenty use case. I dont understand the WP treat them as legacy…

    • This reply was modified 6 months, 2 weeks ago by Lrrr.
    Thread Starter Lrrr

    (@lrrr)

    One more thing occurred to me, think about the problem the other way around.
    Do not use the above code.
    Create a child theme and in it an attachment page and try the difference in front without DFI and with DFI. Respectively with uninstalled and installed DFI. How come the image in the content block is rendered in one case and not in the other? How come there is a difference in behavior on a single attachment page? Thank you.

    Plugin Author Jan-Willem

    (@janwoostendorp)

    Hi,

    As far as I tested everything seems to work as intended. Unfortunately I won’t have time available in the near future to dig deeper.
    I can see you investigated this deeply, and I appreciate that.
    Image management has never been a priority for WordPress.

    How come there is a difference in behavior on a single attachment page?

    In a fresh install with just DFI, the difference is that the attachment-post-type does not support featured images by default, so DFI doesn’t do anything.

    I can see you investigated this deeply, and I appreciate that.
    Image management has never been a priority for WordPress.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Severe issue – not displays attachment page image after uninstall’ is closed to new replies.