Last active
February 26, 2020 18:25
-
-
Save tedgeving/f71de41146b6600969db856d47460cb9 to your computer and use it in GitHub Desktop.
Add featured image to a WordPress page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Themes must declare support for the Featured Image function before | |
* the Featured Image interface will appear on the Edit screen. | |
* add_theme_support( 'post-thumbnails' ); | |
* https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ | |
*/ | |
?> | |
<?php if (has_post_thumbnail()): | |
$image_url = wp_get_attachment_image_src( get_post_thumbnail_id()); | |
// add custom attached image here | |
else: | |
// default image | |
endif; | |
?> | |
/** | |
* the_title(); will display the title of the first post on a custom blog page. | |
* either option below will display the title of the custom page. | |
**/ | |
<?php echo apply_filters('the_title',get_page( get_option('page_for_posts') )->post_title); ?> | |
// Or | |
<?php echo single_post_title(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment