Support » Fixing WordPress » Exclude one word from title when using Title Php function

  • I want to use a title PHP function to display a title in an ad code I was giving, it’s a ringtone ad code and require you have the Artist and the Title of the song, all my titles end with the word “Lyrics”, I was wondering if there was a way I could exclude that one word from there in the php <?php the_title(); ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • You could using the PHP function str_replace: http://uk1.php.net/str_replace

    <?php echo str_replace('Artist', '', get_the_title()); ?>

    Thread Starter sevenkader

    (@sevenkader)

    So i replace the “Artist” in there with “Lyrics”, and the word “Lyrics” will be exclude from the title (It won’t show?)

    Example, using that code will make Bob Hello Lyrics –> Bob Hello
    ?

    Thread Starter sevenkader

    (@sevenkader)

    It worked thank you, I just want to know how to add other words? Because it doesnt work for different capitalization, “Lyrics” doesn’t work for “LYRICS” or “lyrics”, is there I can add it in there?

    Thread Starter sevenkader

    (@sevenkader)

    Nevermind I got it in the link you provided.
    But there’s also one thing I want to know,

    Is it possible to delete the beginning of a title?

    For example, if I want to delete anything that comes behind the “-” or “–”, including that in itself

    Example: Bob Billy – Hello Lyrics –> Hello

    For a more complex/flexible search and replace your probably going to want to use regex: http://uk1.php.net/preg_replace

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Exclude one word from title when using Title Php function’ is closed to new replies.