0

I have a wordpress site with the 10 latest posts shown on the homepage.

I need to modify some text (because of duplicate content) on homepage but not on post page.

I try to modify the following line in index.php like this :

php the_content(Read more ...');

php the_content(Read more ...') . $content = str_replace('XXX', 'YYY');

But it's not working and i can't find a solution.

Can anybody help? Thank you.

0

the_content(Read more ...') echoes the stuff straight out so you can't modify it with str_replace after the fact.

If you wanna use str_replace you need to do something along the lines of

   $content = get_the_content( 'Read more ...' );
   $content = apply_filters( 'the_content', $content );
   $content = str_replace( ']]>', ']]>', $content );
   $content = str_replace( 'xxx', 'yyy', $content );
   echo $content;

and replace xxx and yyy with the real stuff ofc.

-1

I found the solution here is the working code :

   $content = get_the_content( 'Read more ...' );
   $content = str_replace( 'XXX', 'YYY', $content );
   echo apply_filters( 'the_content', $content );

Thank you.

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.