How to change the value of the meta tag?

2

I'm trying to change the value of meta tags with data coming from the database, however they are not populated inside the tags. The value is normally retrieved and displayed inside the script when the view-source is enabled but the content of the meta tag is still empty.

<script type="text/javascript">
$(function(){
    $('meta[name="author"]').attr('content','Marcelo de Andrade');
    $('meta[name="description"]').attr('content','zzzzzzzzz');
    $('meta[name="keywords"]').attr('content','');

});
</script>

<meta name="author" content="" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta property="og:title" content=""/>
<meta property="og:url" content=""/>

<script type="text/javascript">
    $(function(){
        $('meta[name="author"]').attr('content','<?php echo $owner->name ?>');
        $('meta[name="description"]').attr('content','<?php echo $group->elevatorpitch ?>');
        $('meta[name="keywords"]').attr('content','<?php echo $group->tags ?>');
        $('meta[property="og:title"]').attr('content','<?php echo $group->name ?>');
        $('meta[property="og:url"]').attr('content','<?php echo ideas_url($group) ?>');
    });
</script>
    
asked by anonymous 13.06.2014 / 19:52

1 answer

6

"View source" shows the response served to the HTTP request. You can not change the content of this response using a client-side language.

JavaScript changes the DOM that is the structural representation of the document. You can view a serialized representation of the DOM through developer tools (F12 in Chrome, Firefox or IE), where you will see that your meta elements have content updated by JS.

That said, a number of crawlers do not execute (or execute in a limited way) JavaScript, so for purposes of SEO

<meta name="author" content="<?php echo $owner->name ?>" />
...
    
13.06.2014 / 20:03