Search code examples
htmlmeta-tags

How can I retrieve information from the <meta> tag and display it on a webpage?


For example, if I have the following code:

<head>
    <meta name="description" content="Question">
    <meta name="keywords" content="StackExchange, Webmasters">
    <meta name="author" content="Jon Doe">
</head>

I need the following to be displayed somewhere on the webpage:

  • Description: Question
  • Keywords: StackExchange, Webmasters
  • Author: Jon Doe

How could I achieve this?


Solution

  • In PHP, you would first grab the Meta information with get_meta_tags() as an array and echo the different meta tags to wherever you want them to be displayed on your page.

    For example:

    $metastealer = get_meta_tags('http://yourdomain.com');
    echo $metastealer['description'];
    echo $metastealer['keywords'];
    echo $metastealer['author'];
    

    More information here, here and if something doesn't quite work right probably here.