Site logo

Archived topic

Hook latest post

3 replies · Started by Kle on June 19, 2019

Viewing posts 1–4 of 4

Hi,

Is it possible to put a snippet of the latest post (only the post title is fine) anywhere on the website using a hook?

Hi there,

you could add this PHP snippet to the a Hook, make sure to Check Execute PHP:

<?php
$args = array( 'numberposts' => 1 );
$lastposts = get_posts( $args );
?><div class="latest-post"><?php
    foreach($lastposts as $post) : setup_postdata($post); ?>
	    <h2><a class="latest-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
	    <?php the_excerpt(); ?>
    <?php endforeach; ?>
</div>

Hi David,

It didn't worked for me, displayed the title of the page. And I am actually trying to put it on the header "above header", maybe with an Element would be better?

This archived topic is closed to new replies.