简体   繁体   中英

php strstr function not work in wordpress tag.php file

i add following codes in WordPress theme tag.php file

<?php
    while ( have_posts() ) :
        the_post();
        $title = strstr(the_title(), '|', true);
        $link = get_permalink();
        echo '<a class="w3-bar-item w3-button" href="'.$link.'" target="_top" rel="noopener noreferrer">'.$title.'</a>';
    endwhile;
?>

it seems PHP strstr function not working in this file and $title not printed within a tag.
thanks in advance

You sould replace the third argument of the_title() by false:

$title = strstr(the_title(), '|', true);

to

$title = strstr(the_title('','',false), '|', true);

(void|string) Void if $echo argument is true, current post title if $echo is false.

Source: https://developer.wordpress.org/reference/functions/the_title/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM