0

I have a media URL in each page from my database. I play the media with JavaScript code and I have to include it in my page so the JS cat get the media URL and play it. Is it OK to include the URL in a <span> tag and hide it with CSS or is that likely to get my site penalized by search engines for hidden text? Should I include this URL in another way?

Example:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <span id="urlishere" style="display: none;"><? echo $urlfromdatabase; ?></span>

    <script>
        linkmusic = document.getElementById("urlishere").innerHTML;
        music = new Audio(linkmusic);
        music.play();
    </script>

  <!-- I want to know if Google has any problem with this hidden URL on the page? -->
</body>

</html>
0
0

I would recommend putting the URL into a data attribute. Attributes are not visible to the user so you wouldn't have to worry about hidden text with CSS

<span id=linkishere data-url="<? echo $urlfromdatabase; ?>">

Then your JavaScript could be:

new Audio(document.getElementById("urlishere").dataset.url).play()

Alternately you could just embed the URL directly into the JavaScript:

new Audio("<? echo $urlfromdatabase; ?>").play()

Your original solution isn't awful. Search engines would be very unlikely to penalize your site for hiding an HTML element containing a URL. The content that isn't keyword rich, so it wouldn't be something users would be likely to search for. In addition, Google renders pages and indexes text that actually appears on the page rather than what appears in the source code.

1
  • Thanks Stephen :)
    – mmdeshoon
    Nov 5 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.