How to give paged links custom title?

Here’s a way to support pagination titles of the form: <!–nextpage(.*?)?–> in a simlar way as the core supports <!–more(.*?)?–>. Here’s an example: <!–nextpage Planets –> Let’s talk about the Planets <!–nextpage Mercury –> Exotic Mercury <!–nextpage Venus–> Beautiful Venus <!–nextpage Earth –> Our Blue Earth <!–nextpage Mars –> The Red Planet with the output … Read more

wp_nav_menu: show menu only if one exists, otherwise show nothing

Use has_nav_menu(), and test for theme_location, rather than menu_id: <?php if ( has_nav_menu( $theme_location ) ) { // User has assigned menu to this location; // output it wp_nav_menu( array( ‘theme_location’ => $theme_location, ‘menu_class’ => ‘nav’, ‘container’ => ” ) ); } ?> You can output alternate content, by adding an else clause. EDIT You … Read more

How to display last 3 posts (recent posts) in a static page?

I usually use this approach: wrong approach <?php query_posts( array( ‘category_name’ => ‘news’, ‘posts_per_page’ => 3, )); ?> <?php if( have_posts() ): while ( have_posts() ) : the_post(); ?> <?php the_excerpt(); ?> <?php endwhile; ?> <?php else : ?> <p><?php __(‘No News’); ?></p> <?php endif; ?> With the help of @swissspidy the correct way is … Read more

Get page content using slug

Use get_posts() and the parameter name which is the slug: $page = get_posts([ ‘name’ => ‘your-slug’ ]); if ( $page ) { echo $page[0]->post_content; } Be aware that the post type in get_posts() defaults to ‘post’. If you want a page use … $page = get_posts([ ‘name’ => ‘your-slug’, ‘post_type’ => ‘page’ ]); If you … Read more