Variable php in meta tag [closed]

0

This is the following, I have an audio player in html5 and javascript, when I try to share a song in the face for example, the post will not with the audio title but only with the title of the page, my question is how can I do so that when sharing is also shown the name of the audio being shared.

I tried to use a variable that takes the name of the running song, but the "og" tag does not recognize html:

<?php $description = '<span class="center" id="npTitle"></span>';?>

I tried to call it like this:

<meta property="og:description" content="<?php echo $description;?>" />

But it does not work, any suggestions, can you solve without having to reshape the entire player? Thanks!

My player: link

    
asked by anonymous 16.02.2018 / 03:09

1 answer

1

Look, from what I saw you want to share the songs by the site's own buttons, apparently this is going to be an Android app made in HTML5, it is not necessary to follow Title or Description , can do for Javascript variables that define a variable in the URL and that PHP starts with the song pointed to by it.

I did not analyze your HTML code to see how it's actually done, but I'll give you a simple example of how I would do it.

<!DOCTYPE html>
<html>
<head>
<style>
.playlist{
    display:block;
    width:100%;
    text-align:center;
    background-color: blue;
}
audio{
    display:block;
    width:32px;
    height:32px;
    background-color: grey;
}
</style>
<script>
<?php
if(isset($_GET['ip']) && !empty($_GET['ip'])){
    echo "var ip = '".$_GET['ip']."';\n"; //Pegar nome da playlist
    if(isset($_GET['tck']) && !empty($_GET['tck'])){
        echo "var tck = ".$_GET['tck'].";\n";
    }else{
        echo "var tck = 1;\n";
    }
?>
function playAudio(tgt){
    tck = tgt; //Alterar variavel Global para compartilhamento
    var tracks = document.getElementsByTagName('audio');
    for(t=0;t<tracks.length;t++){
        tracks[t].pause();
        tracks[t].currentTime = 0;
        tracks[t].style.backgroundColor = "grey";
    }
    tracks[tgt-1].play();
    tracks[tgt-1].style.backgroundColor = "yellow";
}

function shareTrack(s){
    var url = "http://www.meusite.com/player/?ip="+ip+"&tck="+tck;
    alert("\nCompartilhando no "+s+" o link\n\n"+url);
}
</script>
</head>
<body onload="playAudio(tck)">
<a class="playlist" href="#" id="1" onclick="playAudio(this.id)"><audio src="http://developer.mozilla.org/@api/deki/files/2926/=AudioTest_(1).ogg"></audio>Audio1</a><br/><aclass="playlist" href="#" id="2" onclick="playAudio(this.id)"><audio src="http://developer.mozilla.org/@api/deki/files/2926/=AudioTest_(1).ogg"></audio>Audio2</a><br/><aclass="playlist" href="#" id="3" onclick="playAudio(this.id)"><audio src="http://developer.mozilla.org/@api/deki/files/2926/=AudioTest_(1).ogg"></audio>Audio3</a><br/><aclass="playlist" href="#" id="4" onclick="playAudio(this.id)"><audio src="http://developer.mozilla.org/@api/deki/files/2926/=AudioTest_(1).ogg"></audio>Audio4</a>[<aonclick="shareTrack(this.innerHTML)">Facebook</a>][<a onclick="shareTrack(this.innerHTML)">Whatsapp</a>]
<?php
}else{
?>
</script>
</heead>
<body>
<a href="?ip=playlist1">Playlist1</a><br />
<a href="?ip=playlist2">Playlist2</a><br />
<a href="?ip=playlist3">Playlist3</a><br />
<?php }?>
</body>
</html>
    
16.02.2018 / 21:32