When building a blog website with Mosaic Builder, providing an easy way for visitors to navigate between blog posts is essential for a better user experience.
Previous and Next Post navigation allows readers to move between individual articles without returning to the blog archive page.
In this tutorial, we will create a custom Previous and Next Post navigation using a WordPress shortcode and display it inside Mosaic Builder using its built-in Shortcode element.
We will also add custom CSS to create a clean, modern, and responsive navigation design.
What We Will Build
We will create a navigation section that displays:
- Previous Post: A link to the older blog post.
- Next Post: A link to the newer blog post.
- Post Titles: Dynamically display the titles of adjacent posts.
- Navigation Arrows: Show left and right arrows for intuitive navigation.
- Responsive Design: Display two columns on desktop and a stacked layout on mobile devices.
- Hover Effects: Add smooth transitions for a more interactive experience.
The navigation will automatically change depending on the blog post being viewed.
Why Add Previous and Next Post Navigation?
Adding post navigation to your blog offers several advantages.
1. Better User Experience
Visitors can easily move between related or chronologically adjacent articles without returning to the main blog page.
2. Improved Content Discovery
Previous and Next navigation helps readers discover other articles published on your website.
3. Better Internal Linking
Navigation links create connections between your blog posts, helping visitors and search engines discover content.
4. Increased Reader Engagement
By making navigation easier, visitors may be encouraged to explore additional articles.
5. Automatic Navigation
Once implemented, the navigation automatically updates for each blog post. You do not need to manually edit links whenever you publish a new article.
Step 1: Create the Previous and Next Post Shortcode
First, we need to register a custom WordPress shortcode.
Add the following PHP code to your child theme’s functions.php file or a custom functionality plugin.
You can also use a PHP code snippets plugin.
function mosaic_post_navigation_shortcode( $atts ) {
if ( ! is_singular( 'post' ) ) {
return '';
}
$atts = shortcode_atts(
array(
'same_category' => 'no',
),
$atts,
'mosaic_post_navigation'
);
$same_category = 'yes' === $atts['same_category'];
$previous_post = get_previous_post( $same_category );
$next_post = get_next_post( $same_category );
if ( ! $previous_post && ! $next_post ) {
return '';
}
ob_start();
?>
<nav class="mosaic-post-navigation"
aria-label="Post navigation">
<?php if ( $previous_post ) : ?>
<a class="mosaic-post-nav-item mosaic-post-prev"
href="<?php echo esc_url( get_permalink( $previous_post ) ); ?>">
<span class="mosaic-nav-arrow" aria-hidden="true">
←
</span>
<span class="mosaic-nav-content">
<span class="mosaic-nav-label">
Previous Post
</span>
<span class="mosaic-nav-title">
<?php echo esc_html( get_the_title( $previous_post ) ); ?>
</span>
</span>
</a>
<?php endif; ?>
<?php if ( $next_post ) : ?>
<a class="mosaic-post-nav-item mosaic-post-next"
href="<?php echo esc_url( get_permalink( $next_post ) ); ?>">
<span class="mosaic-nav-content">
<span class="mosaic-nav-label">
Next Post
</span>
<span class="mosaic-nav-title">
<?php echo esc_html( get_the_title( $next_post ) ); ?>
</span>
</span>
<span class="mosaic-nav-arrow" aria-hidden="true">
→
</span>
</a>
<?php endif; ?>
</nav>
<?php
return ob_get_clean();
}
add_shortcode(
'mosaic_post_navigation',
'mosaic_post_navigation_shortcode'
);
How Does This Code Work?
The PHP snippet uses several native WordPress functions.
add_shortcode()
Registers our custom shortcode named [mosaic_post_navigation].
is_singular('post')
Ensures that the navigation only appears on individual WordPress blog posts.
get_previous_post()
Retrieves the previous published post in chronological order.
get_next_post()
Retrieves the next published post in chronological order.
get_permalink()
Returns the URL of each adjacent blog post.
get_the_title()
Retrieves the title of each post.
We also use WordPress escaping functions to output the post URL and title safely.
The shortcode automatically hides unavailable navigation links, such as the Previous link on the oldest post or the Next link on the newest post.
Step 2: Add Custom CSS for the Navigation Design
Now that our shortcode is ready, we can improve its appearance using custom CSS.
The following CSS creates a modern two-column navigation layout with smooth hover effects.
/* Mosaic Builder - Previous/Next Post Navigation */
.mosaic-post-navigation {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 20px;
margin: 35px 0;
}
.mosaic-post-nav-item {
display: flex;
align-items: center;
gap: 16px;
padding: 24px;
background: #ffffff;
border: 1px solid #e5e7eb;
border-radius: 12px;
color: #111827;
text-decoration: none;
min-width: 0;
transition: all 0.25s ease;
}
.mosaic-post-nav-item:hover {
background: #f8faff;
border-color: #2563eb;
transform: translateY(-3px);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.06);
}
.mosaic-post-next {
grid-column: 2;
justify-content: flex-end;
text-align: right;
}
.mosaic-nav-content {
display: flex;
flex-direction: column;
gap: 6px;
min-width: 0;
}
.mosaic-nav-label {
font-size: 13px;
font-weight: 500;
color: #6b7280;
}
.mosaic-nav-title {
font-size: 16px;
font-weight: 600;
line-height: 1.5;
overflow-wrap: anywhere;
}
.mosaic-nav-arrow {
font-size: 24px;
color: #2563eb;
flex-shrink: 0;
}
/* Mobile Responsive Layout */
@media (max-width: 600px) {
.mosaic-post-navigation {
grid-template-columns: 1fr;
gap: 12px;
}
.mosaic-post-nav-item {
padding: 18px;
}
.mosaic-post-next {
grid-column: 1;
}
}
/* Keyboard Accessibility */
.mosaic-post-nav-item:focus-visible {
outline: 2px solid #2563eb;
outline-offset: 3px;
}
/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
.mosaic-post-nav-item {
transition: none;
}
.mosaic-post-nav-item:hover {
transform: none;
}
}
Where Should You Add the CSS?
You can add the CSS to your theme’s stylesheet or your website’s global CSS.
Alternatively, Mosaic Builder provides a Code element that supports custom CSS. If using this approach, wrap the CSS inside <style> tags and configure the insertion location appropriately.
If you had the Mosaic Editor Plus add-on, you could directly add the custom CSS to the template by using the Document CSS editor.

Step 3: Open Single Post Template in Mosaic Builder
After registering the shortcode and adding the CSS, the next step is to insert it into your Mosaic Builder layout.
- Open the WordPress Dashboard.
- Navigate to the Mosaic Builder templates area.
- Open the template assigned to your single blog posts.
- Launch the Mosaic Builder editor.
- Locate the section where you want to display the post navigation.
Recommended placement: Add the navigation section immediately after your blog post content and before the related posts or comments section.
This placement allows readers to continue exploring your content when they finish reading an article.
Step 4: Add the Shortcode Element in Mosaic Builder
Mosaic Builder includes a native Shortcode element, making it easy to display WordPress shortcode output inside your layout.
Follow these steps:
- Open the Add panel in the Mosaic Builder editor.
- Locate the WordPress group.
- Find the Shortcode element.
- Drag the Shortcode element into your single post template, below the Post Content element.
- Select the Shortcode element.
- Open its Settings tab.
- Enter the following shortcode in the shortcode field:
[mosaic_post_navigation]
That’s it!
The Shortcode element will process the shortcode and display the Previous and Next Post navigation on the front end.
Important: Mosaic Builder currently displays the shortcode text rather than its rendered content inside the editor canvas. To see the actual navigation design, open the front-end preview.
Step 5: Preview the Post Navigation
Once you have inserted the shortcode, save your template and open a published blog post on the front end.
You should now see the Previous and Next Post navigation displayed below the blog post content.
The navigation automatically retrieves the adjacent published posts.
For example, suppose you have three blog posts:
- Getting Started with Mosaic Builder
- How to Create a Single Post Template
- How to Customize Mosaic Builder Layouts
When viewing the second article, WordPress will display the first article as the Previous Post and the third article as the Next Post, assuming those posts are ordered chronologically.
The displayed titles and links update automatically according to the current post.
Step 6: Display Previous and Next Posts from the Same Category
Sometimes you may want readers to navigate only between posts belonging to the same category.
For example, when someone is reading a Mosaic Builder tutorial, you may want the navigation to display other posts from that category rather than articles from unrelated categories.
Our shortcode supports this feature.
Simply use:
[mosaic_post_navigation same_category="yes"]
With this option enabled, WordPress retrieves adjacent posts that share a category with the current post.
If there is no eligible adjacent post, the corresponding navigation link will not appear.
To restore the default chronological navigation across all categories, use:
[mosaic_post_navigation]
Step 7: Customize the Navigation Design
You can easily customize the navigation design to match your website’s branding.
Change the Arrow Color
To change the arrow color, update the following CSS:
.mosaic-nav-arrow {
color: #16a34a;
}
Change the Hover Background
.mosaic-post-nav-item:hover {
background: #f0fdf4;
border-color: #16a34a;
}
Change the Border Radius
For more rounded navigation cards:
.mosaic-post-nav-item {
border-radius: 20px;
}
Change the Post Title Font Size
.mosaic-nav-title {
font-size: 18px;
}
You can adjust the padding, spacing, colors, typography, and hover effects to suit your website design.
Common Issues and Troubleshooting
1. The Shortcode Appears as Text Instead of Navigation
If [mosaic_post_navigation] appears as plain text on the front end, make sure your PHP shortcode has been registered successfully.
Check that the PHP code is active and that the shortcode name matches exactly.
2. Navigation Is Not Showing in the Mosaic Builder Editor
This is expected behavior for the native Mosaic Shortcode element.
The editor displays the shortcode itself rather than the generated HTML. Use the front-end preview to view the navigation.
3. Previous or Next Post Is Missing
WordPress displays navigation only when an eligible adjacent published post exists.
For example, the oldest published post may not have a Previous Post link, while the newest published post may not have a Next Post link.
4. Navigation Is Not Showing on Pages
Our shortcode intentionally uses the following condition:
if ( ! is_singular( 'post' ) ) {
return '';
}
This limits the navigation to individual blog posts rather than regular WordPress pages.
5. CSS Styles Are Not Working
Make sure your custom CSS is loaded on the front end.
Also, check whether your theme or other styles are overriding the navigation CSS.
You can use your browser’s developer tools to inspect the generated elements and identify conflicting CSS rules.
Frequently Asked Questions
Can I use this shortcode with Mosaic Builder?
Yes. Mosaic Builder supports standard WordPress shortcodes through its built-in Shortcode element.
Do I need a separate WordPress plugin?
No additional navigation plugin is required. You only need the custom PHP shortcode and CSS.
You can place the PHP code in a child theme or a code snippets plugin.
Does the navigation update automatically?
Yes. The shortcode retrieves adjacent published blog posts dynamically, so you do not need to manually update links.
Can I show only posts from the same category?
Yes. Use the same_category="yes" attribute to limit navigation to posts sharing a category with the current article.
Is the navigation mobile-friendly?
Yes. The provided CSS displays a two-column layout on larger screens and switches to a single-column layout on smaller screens.
Can I customize the navigation colors and typography?
Absolutely. You can change the colors, spacing, fonts, borders, and hover effects by modifying the CSS.
Can I use this shortcode with other WordPress builders?
Yes. Because this is a standard WordPress shortcode, it can also work with other page builders that support shortcode execution.
Alternative Method: Create Previous and Next Post Navigation Without Custom Code
Update – October 26, 2026
Following feedback from the Mosaic Builder development team, we’d like to highlight another way to create Previous and Next Post navigation using Mosaic Builder’s built-in features.
Although the method explained earlier in this tutorial uses a custom PHP shortcode and CSS, Mosaic Builder also supports creating dynamic post navigation without writing custom PHP code.
By combining Mosaic’s Dynamic Sources, Data Variables, and Conditional Visibility features, you can build fully customizable Previous and Next Post navigation directly inside the visual editor.
Thanks to the Mosaic Builder team for pointing out this native approach!
How Does the No-Code Method Work?
Mosaic Builder allows you to define dynamic data sources for individual Div elements.
Instead of manually retrieving adjacent posts with WordPress PHP functions, you can configure a Div element to retrieve the previous or next post based on its publication date.
Once configured, you can dynamically display information such as:
- Previous or next post title
- Post permalink
- Featured image
- Publication date
- Other available post data
You can then style these elements visually using Mosaic Builder’s native design controls.
Step 1: Create the Previous Post Navigation
- Open your Single Post template in Mosaic Builder.
- Add a Div element where you want the navigation to appear.
- Open the Div element’s Settings tab.
- Find Dynamic Sources and click the + icon.
- Select Posts (or your preferred custom post type) as the source.
- Add a Filter rule using the following settings:
- Post variable key: Published date GMT
- Operator: Less than
- Value: Dynamic Code
- Enter the following dynamic expression:
@DATE('Y-m-d H:i:s', @VAR('post/publish_timestamp'))
- Apply the filter and configure the ordering:
- Order by: Publish date
- Order: Descending
Now, elements placed inside this Div can access the previous post’s dynamic data.
For example, you can add a Text element to display the post title and configure a link using the post’s permalink variable.
Step 2: Create the Next Post Navigation
Repeat the same process for the Next Post navigation, but change two settings:
- Filter Operator: Greater than
- Order by Publish date: Ascending
Keep the same dynamic date expression.
This configuration retrieves the next post chronologically, allowing you to display its title, permalink, featured image, and other dynamic information.
Step 3: Customize the Navigation Design
Once both dynamic sources are configured, you can create your preferred navigation layout using Mosaic Builder’s visual controls.
For example, you could design two navigation cards:
- ← Previous Post: Display the previous post title and link.
- Next Post →: Display the next post title and link.
You can customize the layout, spacing, typography, borders, backgrounds, hover effects, and responsive behavior without writing custom CSS.
Step 4: Hide Navigation When No Adjacent Post Exists
On the oldest or newest blog post, one of the navigation links might not have a corresponding post.
Mosaic Builder’s Conditional Visibility feature can help handle these situations.
You can configure a visibility condition that checks whether the post ID from the Div’s dynamic source is greater than 0.
This prevents navigation elements from appearing when no matching previous or next post is available.
Which Method Should You Use?
Both methods can create dynamic Previous and Next Post navigation, but they offer different workflows.
Native Mosaic Builder Method
This is a good choice if you prefer working entirely inside the visual editor, want to avoid additional PHP code, and want to customize your navigation using Mosaic’s built-in design tools.
Custom PHP Shortcode Method
The shortcode method explained earlier in this tutorial remains useful if you prefer managing navigation markup through PHP, need specific WordPress functionality such as the included same-category navigation option, or want direct control over the generated HTML.
Final Thoughts
Mosaic Builder provides powerful dynamic data capabilities that can eliminate the need for custom PHP code in many common WordPress development scenarios.
We appreciate the Mosaic Builder team for sharing this alternative approach with us and the community.
For the complete official instructions, including dynamic source configuration, filtering, and conditional visibility, visit:
Official Mosaic Documentation – How to Insert Variables from the Next/Previous Post
Whether you choose the native visual approach or the custom shortcode solution, both methods give you flexibility to build dynamic post navigation that suits your website’s requirements.

