0

with this code

$wptitle = str_replace(array('Versandkostenfrei'), 'Kostenloser Versand', $wptitle);

I exchange words in one of my loops.

Now I am trying to change a word that is called with echo $term->name; how do I implement that? I tried

<?php 
$wptitle = str_replace(array(' .echo ($term->name;)'), '', $wptitle); 
?>

but its obviously not working :-(

  • What is .echo ($term->name;) in an array? – Gufran Hasan Nov 21 '18 at 14:18
  • Can you show the part where echo $term->name; occurs? (couple of lines before and after so we have context) – kero Nov 21 '18 at 14:19
  • I am using ´<?php echo $term->name; ?>´ to show a Word in a custom taxonomy/theme – joloshop Nov 21 '18 at 14:21
  • You'll probably want something like $wptitle = str_replace($term->name, 'neuer Text', $wptitle); (also, this isn't a wordpress question. this is a PHP question) – Chris G Nov 21 '18 at 14:29
  • thanks working, sorry using it in my Wordpress theme, but you are right its php sorry und thanks! – joloshop Nov 21 '18 at 14:34
1

The PHP echo language construct that outputs the parameters passed. You don't want to do that in the middle of str_replace. To replace $term->name with an empty string, use:

$wptitle = str_replace( $term->name, '', $wptitle );

Then when you want to print it, use:

echo $wptitle;

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.