Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell Reddit to ignore my Logo for the Thumbnail?

When a user shares content from my website, often the image appearing in the thumbnail is the logo of the website instead of the image itself.

How can I tell reddit to ignore the logo ?

I searched a lot and found answers on how to specify which image reddit should use with the og image meta tag, but I can't do that since my website is part UGC, meaning I wouldn't know what is the absolute URL for every image.

For example: reddit not pulling scraping image on link post

EDIT:

This doesn't seem to be working on my end. Does it work on yours ?

<script>
function img_find() {
    var imgs = document.getElementsByTagName("img");
    var imgSrcs = [];

    for (var i = 0; i < imgs.length; i++) {
        imgSrcs.push(imgs[i].src);
    }

    return imgSrcs;
}var result = img_find();
$("meta[property='og:image']").attr("content", result[1]);
</script>
like image 533
Coder1000 Avatar asked May 24 '17 09:05

Coder1000


2 Answers

Your code

$("meta[property='og:image']").attr("content", result[1]);

is almost the solution. Let's do the last step:

$("meta[property='og:image']")
    .attr("content", $('css_selector_of_the_img')[0].src);

So what is css_selector_of_the_img? Since you have the website logo, I'd assume that you had some HTML around your image. Probably the image has a className or placed into a container e.g. css_selector_of_the_img could be div.content img or img.uploaded whatever. And throw away your img_find function J.

like image 195
Kosh Avatar answered Nov 16 '22 02:11

Kosh


I found the solution.

Adding property="og:image" to the <img> I want selected worked.

like image 39
Coder1000 Avatar answered Nov 16 '22 02:11

Coder1000