How to make the first letter of a post title uppercase, in a plugin?

I’m making a plugin that makes the first letter of the first word in a post title uppercase, if it was lowercase. I’m a beginner, so it’s simple, but even so I struggle! The plugin can be activated without errors but it doesn’t have the desired effect. Here’s the code:

<?php

//Changes the first letter of post titles to uppercase

function shikharfirstletter() {

$title = get_the_title();
$title_first_letter = substr($title, 0);

if($title_first_letter = ‘a’) {
return str_replace($title_first_letter, ‘A’, $title);
}

elseif($title_first_letter = ‘b’) {
return str_replace($title_first_letter, ‘B’, $title);
}

//So on for the other letters…
}

add_filter( ‘wp_title’, ‘shikharfirstletter’ );

?>

Any idea where I’m going wrong?

Read more here:: How to make the first letter of a post title uppercase, in a plugin?

Leave a Reply

Your email address will not be published. Required fields are marked *