I have a site that reviews movies (DVD/Blu-ray, etc.)So every review in a particular category will have (Blu-ray) after the title, another will have DVD and so forth. i.e. Avengers: Infinity War (Blu-ray). I want to trim the format of the disc (Blu-ray) from the page title and I have this code, but it's not working. Wasn't sure what the issue was.
<span style="color: #ffffff">About <?php if (in_category('5447') ):?>
<?php
echo str_replace("(Blu-ray)"," ","<?php the_title(); ?>");
?>
</span>
<?php endif; ?>
So, in essence, I can grab the title and it will read: Avengers: Infinity War (Blu-ray)
but I want it to read: Avengers: Infinity War
I have a site that reviews movies (DVD/Blu-ray, etc.)So every review in a particular category will have (Blu-ray) after the title, another will have DVD and so forth. i.e. Avengers: Infinity War (Blu-ray). I want to trim the format of the disc (Blu-ray) from the page title and I have this code, but it's not working. Wasn't sure what the issue was.
<span style="color: #ffffff">About <?php if (in_category('5447') ):?>
<?php
echo str_replace("(Blu-ray)"," ","<?php the_title(); ?>");
?>
</span>
<?php endif; ?>
So, in essence, I can grab the title and it will read: Avengers: Infinity War (Blu-ray)
but I want it to read: Avengers: Infinity War
Share Improve this question asked Apr 12, 2020 at 16:05 user34872user34872 153 bronze badges2 Answers
Reset to default 0the_title()
will directly output the title - for your purpose in a string manipulation, you need to use get_the_title()
https://developer.wordpress/reference/functions/get_the_title/
you also have some php syntax error;
try to use:
<?php
echo str_replace( "(Blu-ray)"," ", get_the_title() );
?>
you have mistake hire :
echo str_replace("(Blu-ray)"," ","<?php the_title(); ?>");
should be : echo str_replace( "(Blu-ray)", "", get_the_title() );
1 - the_title() echo directly the title, you cannot do enything whit the title.
2- when call the str_replace() dot put inside php tags ;)