0

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)","&nbsp;","<?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

0

the_title() will directly output the title - for your purpose in a string manipulation, you need to use get_the_title() https://developer.wordpress.org/reference/functions/get_the_title/

you also have some php syntax error;

try to use:

<?php
echo str_replace( "(Blu-ray)","&nbsp;", get_the_title() );
?>
| improve this answer | |
  • That seems to have done the trick. I don't know how, but I won't argue with results. Thank you! – user34872 Apr 12 at 16:37
0

you have mistake hire :

echo str_replace("(Blu-ray)","&nbsp;","<?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 ;)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.