I have a field to display a custom page title
<title><?php echo the_field('custompagetitle'); ?></title>
Existing page titles are PAGE ONE, PAGE TWO, etc. but I am looking for a way to convert them to Capitalized like Page One, Page Two, etc.
HTML titles can not be targeted by css so I have searched for javascript or other methods to capitalize them.
This doesn’t work
<title><?php echo ucwords(strtolower(the_field('custompagetitle'))); ?></title>
but not using ACF fields does work
<title><?php echo ucwords(strtolower("PAGE TWO")); ?></title>
Is there any way to capitalize fields?
Your first issue is that you are using the_field(). the_field() echoes the value. You need to use get_field(). doing this echo the_field(...)
is like doing this echo(echo get_field(...))
Using get field this should work
echo ucwords(strtolower(get_field('custompagetitle')));