Home Ghost post_title from my WP LOOP script
Reply: 1

Ghost post_title from my WP LOOP script

ragulin
1#
ragulin Published in 2017-09-14 02:05:57Z

The code below is displaying the title in black text before it displays blue title with hyperlink under it.

I only want the link to appear.

if ( $query2->have_posts() ) {
    // The 2nd Loop
    while ( $query2->have_posts() ) {
        $query2->the_post();
                 if ($post->ID == $do_not_duplicate)
                continue;
                $permalink = get_the_permalink($query2->post->ID);
                $ID = $post->ID;
                $titleAtribute = the_title_attribute();
                $title = get_the_title();
        echo '<h2 id="post-' .$ID.' ">
                <a href="'.$permalink.'" rel="bookmark" title="Permanent Link to '.$permalink.' ">
                   '.$title.'</a></h2>';
    }

    // Restore original Post Data
    wp_reset_postdata();
}

For example, on my website: http://skkelti.cz/, the following text appears in black above the link with the same text:

-Martin Davídek ml. : „Fanoušci jsou vždy to, co vás žene kupředu“-

Where is this coming from and what do I need to do to stop it from appearing?

FluffyKitten
2#
FluffyKitten Reply to 2017-09-14 03:02:57Z

The problem is with the_title_attribute(). This is displaying the value directly instead of returning it.

The function accepts echo in $args to specify whether to display or return the value. The default value is true (to display it), so pass false to return the value e.g.:

$titleAtribute = the_title_attribute('echo=0');
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.309044 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO