Sam Weinberg
Sam Weinberg

Reputation: 113

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:

How could I achieve this?

Upvotes: 1

Views: 1618

Answers (2)

unor
unor

Reputation: 96597

Probably not what you want, but you could of course display the attribute values of the actual meta elements with CSS:

head, meta {display:block;}
meta[name="description"]::after {content:"Description: " attr(content);}

Only advisable if you need a simple/quick way to display it for your own site owner’s need. Don’t use this method if you want the content to be accessible to your visitors. In that case you should repeat the content and mark it up accordingly.

Upvotes: 1

David K.
David K.

Reputation: 324

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.

Upvotes: 1

Related Questions