I would remove the last character from tag name in tag archive page, I tried:
<?php
echo substr(<?php single_tag_title(); ?>, 0, -1);
?>
but won't work.
Two things here, one is wrong syntax because you're opening and closing PHP tags twice. The second problem is the wrong usage of single_tag_title()
.
If you want this function to return value instead of outputting it (and you need that because you want to manipulate the string), you need to set the second parameter to false. (see the second example: https://codex.wordpress.org/Function_Reference/single_tag_title )
Also it's a good idea to check if you didn't get an empty result.
So your code should look like this:
<?php
$tag_title = single_tag_title( '', false );
if ( ! empty( $tag_title ) ) {
echo substr( $tag_title, 0, -1 );
}
?>
get_search_query()
. It's the same problem - if you use the function, that displays the output (with the echo
or print
), you won't be able to process is anymore. You need to look for the functions, that return the output without displaying it. In WordPress, there is naming convention that helps with that - the functions that start with the_
(i.e. the_search_query()
) display stuff, and the ones starting with get_
( get_search_query()
) would only return data, so you can process it and display it yourself.
Commented
Aug 23, 2018 at 8:25