Part 1 Learning Objectives
- Master the difference between "the_" and "get_" functions
- Learn core template tags for titles and content
- Understand link and URL functions
- Work with date and time template tags
Understanding Template Tags
Template tags are PHP functions provided by WordPress to display information dynamically. They're the bridge between your database content and what users see on your website.
🔄 The "the_" vs "get_" Pattern
WordPress follows a consistent naming pattern for template tags:
the_* Functions
- Echo output directly
- Used in templates
- Apply filters automatically
- No return value
<?php the_title(); ?>
// Outputs: My Post Title
get_* Functions
- Return values
- Used in PHP logic
- More flexible
- Can be stored in variables
<?php
$title = get_the_title();
echo strtoupper($title);
// Outputs: MY POST TITLE
📄 Title and Content Tags
the_title() / get_the_title()
Displays or retrieves the post title.
| Parameter | Type | Description |
|---|---|---|
| $before | string | Text before title |
| $after | string | Text after title |
| $echo | bool | Echo or return |
the_content() / get_the_content()
Displays the post content with formatting.
Best Practice
Always use the_content() instead of get_the_content() when displaying content, as it applies essential filters like wpautop and shortcode processing.
the_excerpt() / get_the_excerpt()
Displays a short excerpt of the post (55 words by default).
the_title_attribute()
Sanitized version of title for use in attributes.
🔗 Link and URL Tags
the_permalink() / get_permalink()
Displays the permanent link to the post.
get_post_permalink()
Gets permalink for any post type.
the_shortlink()
Displays a shortlink to the post.
wp_get_shortlink()
Retrieves the shortlink for a post.
📅 Date and Time Tags
the_date() / get_the_date()
Displays the post date (only once per day in a list).
the_time() / get_the_time()
Displays the time the post was published.
the_modified_date()
Displays the date the post was last modified.
human_time_diff()
Human-readable time difference.