Jump to content

OpenGraph (?) for my website


mel47
 Share

Recommended Posts

Hi,

I have a really basic question, since I'm not sure in which direction I should search. I want to replicate the behavior we see on social media : the url preview of a website but on my PW site. I guess it should be related to opengraph, but in the other way around. However, I found a lot of information about implementation opengraph metatags, but it's always about adding metadata on your website, not scraping them and displayed them. Someone have pointers to help me to find how I could do that? (I also search for a module but didn't find, but I'm not sure I searched with the good keywords). 

Thanks!

Link to comment
Share on other sites

Does this help?

https://github.com/fusonic/opengraph#retrieve-open-graph-data-from-a-url

You could try without a library, but something like: https://stackoverflow.com/questions/7454644/how-to-get-open-graph-protocol-of-a-webpage-by-php may not not be very reliable.

There is also this: https://www.opengraph.io/examples/php-open-graph-example/ / https://github.com/primeobsession/opengraph-io-php but it hasn't been updated in years so not sure this is a great way to go but might be a useful resource nonetheless.

 

 

  • Like 4
Link to comment
Share on other sites

I just made today a class for Processwire that automates the process quite a bit. It's really basic, I will improve it in the future.

https://github.com/carlitoselmago/opengraphPW

It's used like this:

<head>
	<?php
	include_once("./opengraphPW/opengraphPW.php");
	$OG=new openGraph(
		$page, // current PW page, required
		$pages, // PW pages wire object, required
		$config->urls->templates.'img/cover.jpg', // A general image (1200x628px recomended) for pages like a home page where there's no content image, optional
		"Title of your website"); // A generic title if the home element is called something like "home", optional
	?>
 </head>
  • Like 1
Link to comment
Share on other sites

6 hours ago, carlitoselmago said:

I just made today a class for Processwire that automates the process quite a bit. It's really basic, I will improve it in the future.

https://github.com/carlitoselmago/opengraphPW

It's used like this:


<head>
	<?php
	include_once("./opengraphPW/opengraphPW.php");
	$OG=new openGraph(
		$page, // current PW page, required
		$pages, // PW pages wire object, required
		$config->urls->templates.'img/cover.jpg', // A general image (1200x628px recomended) for pages like a home page where there's no content image, optional
		"Title of your website"); // A generic title if the home element is called something like "home", optional
	?>
 </head>

Hi,
I'm not sure this will solve my problem. If I understand, your module will print og, but I want to do the opposite : grab og from a link.

Correct me if i'm wrong,
Mel

  • Like 1
Link to comment
Share on other sites

8 hours ago, mel47 said:

Hi,
I'm not sure this will solve my problem. If I understand, your module will print og, but I want to do the opposite : grab og from a link.

Correct me if i'm wrong,
Mel

Oh I see, actually I did read your post too quick. It is possible, I did something like that once having a field that would go download automatically some info from a website.

I found this post on stackoverflow that contains a function to do that. 

https://stackoverflow.com/questions/3711357/getting-title-and-meta-tags-from-external-website/4640613

That just grabs the basic meta tags but the opengraph ones are just the same, they allways contain this 

<meta property="og:something" content="something" />
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...