jaredroweseo
jaredroweseo

Reputation: 21

Why won't my image name convert to lowercase in PHP?

Here is the code I'm using:

<img src="/images/<?php strtolower(the_title()); ?>.jpg" border="0" >

Upvotes: 0

Views: 411

Answers (2)

Varol
Varol

Reputation: 1858

Wordpress the_title() function echoes the title by default. You need to set the echo argument to false and echo the lowercase output yourself.

<img src="/images/<?php echo strtolower(the_title('','',false)); ?>.jpg" border="0" />

Upvotes: 4

John Conde
John Conde

Reputation: 219844

It looks like the_title() actually echo's out the title since you don't have an echo statement in your snippet. So your call to strtolower() is basically doing nothing. You'll need to capture the output of the_title() then you can convert it to lower case.

ob_start();
the_title();
$title = $template = ob_get_clean();
<img src="/images/<?php echo strtolower($title); ?>.jpg" border="0" />

Upvotes: 0

Related Questions