• Resolved mike4music

    (@mike4music)


    I have several pages with 2 name titles that I’d like to replace the space with a +, for example a page that echoes Joss Stone for <?php the_title(); ?> i’d like to echo Joss+Stone. I’ve tried <?php echo str_replace(” “, “+”, the_title())?> but this doesn’t work, any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • softwaredriverdownload

    (@softwaredriverdownload)

    Two concerns that I see here:

    1. the_title() only works in the Loop. I suggest make use of single_post_title() instead, it works outside the Loop. And make sure it is single post using:

    ‘<?php if ( is_single(){‘

    2. If using single_post_title(), you can pass it to PHP by specify the second parameter to FALSE e.g.

    ‘single_post_title(”, FALSE)’

    This problem took me some times to figure out (self-taught amateur PHP coder ?? but now its working now in my site https://www.softwaredriverdownload.com , take a look at the meta data, its using the same technique above.

    Thread Starter mike4music

    (@mike4music)

    Thank you for putting me on the right track, I found that using <?php echo get_query_var(‘pagename’); ?>
    works well for me, it’s not a + but at least the – fills in the empty space, thank you again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Trying to Replace Space in the_title()’ is closed to new replies.