简体   繁体   中英

Print inside print php

How do i print INSIDE the defined tag? When it ouputs this code, the_title() gets printed OUTSIDE (before) the h1 tag..

My code is:

        <?php 
            if ( '' != get_the_post_thumbnail() ) {
                print '<p>HEY</p>';
            }
            else {
                print '<div class="page-header row full"><h1 class="page-title" itemprop="headline">', the_title() ,'</h1></div>';
            }
        ?>

i have already tried:

        <?php 
            if ( '' != get_the_post_thumbnail() ) {
                print '<p>HEY</p>';
            }
            else {
                print '<div class="page-header row full"><h1 class="page-title" itemprop="headline">'. the_title() .'</h1></div>';
            }
        ?>

What am i doing wrong?

Thanks

You could do like below:

<?php if ( '' != get_the_post_thumbnail() ): ?>
    <p>HEY</p>
<?php else: ?>
    <div class="page-header row full"><h1 class="page-title" itemprop="headline"><?php the_title(); ?></h1></div>
<?php endif; ?>

Or use get_the_title() (which returns the title value) instead.

Try print "....".get_the_title().".....";

The methods "the_xxxx" print the value, the methods "get_the_xxx" returns the value.

try echo instead of print

echo - can output one or more strings

print - can only output one string, and returns always 1

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