Question

Is it good practice to use PHP to inject text into your alt or title tags? Can a search engine read the title tag or does it just see the code?

This is basically what I was going for

<?php
$title = “testing 123" ;
?>

<h2><?php echo $title; ?></h2>
<img src="images/test/test01.jpg" alt="<?php echo $title; ?>" title="<?php echo $title; ?>" /> 

Or is it better to just do this

<h2><?php echo $title; ?></h2>
<img src="images/test/test01.jpg" alt=" testing 123" title=" testing 123" /> 

Thanks for your help.

Was it helpful?

Solution

A search engine crawls your website just like a user does. They send a HTTP (usually) request and search the page source that is returned from the server (your delivered content, in this case your PHP's output).

This means search engines never see your server side code like PHP, they see exactly the same as a user. So your two solutions are actually identical.

OTHER TIPS

PHP code is not visible to the web browser OR a search engines web crawler.

When php code is executed on the server, only the resulting output buffer is passed to the endpoint (Ex: anything echo'ed or outside php tags).

Try running your above code in a web browser then "view source". What you see is what search engines see.

PHP is a serverside language. This means that the server processes the PHP, and sends on the client-side resources. (in the form of html, css, javascript, and other such handy tools)

Outside of the server, the PHP is never seen. It has already been compiled and run. There is no way for anything to determine how that client-side resource was generated - whether it was dynamically generated or is static.

Your first choice of code should work just fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top