Site logo

Archived topic

Suggestion Page header for pages & posts

30 replies · Started by Peter on July 9, 2017

Viewing posts 16–30 of 31

Yes, if you're using a global page header for all single posts, you won't be able to use only the featured image inside one of your posts. The featured images are used in the global page header. In this case, you would need to use custom code to insert the featured image (not a big deal).

Your code to add the featured image would look something like this:

add_action( 'generate_before_content', 'tu_add_featured_image' );
function tu_add_featured_image() {
    if ( is_singular( 'post' ) && has_post_thumbnail() ) {
        the_post_thumbnail();
    }
}

Yep, added that code and now the featured image shows up under the page header.
http://playground.codebastler.com/first-test-post-with-gp-premium-1-4-alpha/

So as a beta-tester some last thoughts:

- I am using WP since 6 years. For me the featured image was always perceived as part of the content and not so much of the header. Especially when there were galleries, then it was the the most important pic to select as featured image. which will then be used in category & tagged pages.

-Maybe it should be more clarified with the new page header part, what is for pages & posts globally and what is singularly.
For example I can click "featured image"in the page header part and it is not really obvious, that it is only THAT featured image, that will be used globally. In the beginning of testing I assumed, that it WILL BE the featured image of each page or post.

- Eventually one can add a select field in the page header part for pages & posts > "use featured image globally/singularly" - and if singularly then the custom code from you will be hooked.

Cheers
P.

Thank you! I really appreciate your feedback and suggestions! :)

Using a shortcode is another option. You can make this a plugin or add it to your functions.

add_shortcode('thumbnail', 'thumbnail_in_content');

function thumbnail_in_content($atts) {
    global $post;

    return get_the_post_thumbnail($post->ID);
}

And then use [thumbnail] to call the image.

Thanks, Chad. Good solution :)

Can this be added via GP Hooks?

Well, answered my own question. I was able to use it in GP Hooks, but had to wrap it with the <?php ?>.

One thing I noticed was that this makes the Customize > Layout > Blog: Feature Image: Single Post settings irrelevant.

Also, you have to place the code in the GP Hooks block where you want the featured image to be displayed.

Edit:: Found this did not work when I tried using it in the "After Entry Title" section in GP Hooks. How would I be able to use it there?

Sorry..what exactly are you trying to do?

Feel free to open a new topic :)

Sorry, I was asking about using the code from Tom above in GP Hooks to add the Featured Image to the post when you are using the Header module. I guess I should have started with that in my post.

From the searching I did, this topic had the easiest solution to implement.

That's what I used. I was actually asking if that code snippet could be used with GP Hooks, and how.

This is what I found:

Well, answered my own question. I was able to use it in GP Hooks, but had to wrap it with the <?php ?>.

One thing I noticed was that this makes the Customize > Layout > Blog: Feature Image: Single Post settings irrelevant.

Also, you have to place the code in the GP Hooks block where you want the featured image to be displayed.

Edit:: Found this did not work when I tried using it in the “After Entry Title” section in GP Hooks. How would I be able to use it there?

Is there a better way than this?

Try this snippet:

add_action( 'generate_after_entry_title', 'tu_add_featured_image' );
function tu_add_featured_image() {
    if ( is_singular( 'post' ) && has_post_thumbnail() ) {
        the_post_thumbnail();
    }
}

Thanks!

No problem!

Hello,

Could you tell me what is the best way to insert this code and cusomize featured image.

add_action( 'generate_before_content', 'tu_add_featured_image' );
function tu_add_featured_image() {
if ( is_singular( 'post' ) && has_post_thumbnail() ) {
the_post_thumbnail();
}
}

Do I need to install Code Snippets?

Thank youn

This archived topic is closed to new replies.