Celebrating 7 Years! Get up to $30 off GeneratePress Premium!

[Support request] Image Post Caption in Page Header

Home Forums Support [Support request] Image Post Caption in Page Header

Home Forums Support Image Post Caption in Page Header

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #587279
    Kevin

    I use people’s illustrations for the headers of the articles.

    I wanted to put the caption of the images in Page Header, but there is no tag for that. How can I create a tag or shorcode?

    GeneratePress 2.1.2
    GP Premium 1.6.2
    #587381
    Leo
    Staff
    Customer Support

    Hi there,

    Not sure if I understand.

    Caption of which images? Any examples you can provide?

    Let me know 🙂

    #587383
    Kevin

    I want a code that shows the Caption of the highlighted image of the article in Page Header. So I can put the credits of the author of the image along with the author of the same article in the example below:

    null

    #587544
    Tom
    Lead Developer
    Lead Developer

    I’m not sure if it’s possible to add the caption from the image automatically, but you can use the Custom Fields metabox on each page to add a caption custom field.

    Then you can use the custom field template tag within the Page Header content: https://docs.generatepress.com/article/page-header-template-tags/#custom_field-name

    #587623
    Kevin

    The big problem is that I would have to add every time, I use the same illustration in several posts, it is annoying to have to add a custom field, being that I can only once add in the Caption of the media. My old theme did this automatically in the Header. Maybe if creating a shortcode is enough, but I do not know how, I do not know anything about PHP.a

    #587699
    Kevin

    I was able to create the shortcode, it was simple:

    add_shortcode('autor-imagem', 'thumbnail_in_content');
    
    function thumbnail_in_content($atts) {
        global $post;
    
        return get_the_post_thumbnail_caption($post->ID);
    }
    #587704
    David
    Staff
    Customer Support

    Tom / Kevin,

    this is a shortcode i was playing with a while back, it grabs the featured image caption. It works inside the page header, just couldn’t get it to appear inside of the the page header content area:

    function db_featured_image_caption() {
        $get_description = get_post(get_post_thumbnail_id())->post_excerpt;
        if(!empty($get_description)){    
            echo '<div class="featured_caption">' . $get_description . '</div>';
        }
    }
    add_shortcode ('featured-caption', 'db_featured_image_caption' );

    EDIT – Didn’t see your reply Kevin. Good to see you have something working

    #587708
    Kevin

    Thanks xD

    With shorcode that I created I was able to put like this:

    https://skdesu.com/lista-de-nomes-japoneses-masculinos/

    <span class=”titulo-artigo3″>Post by {{post_author}} // Art by [autor-imagem]</span>

    Now I will try to add a CSS color for each category post… It is good puzzle.

    #587714
    David
    Staff
    Customer Support

    Hi Kevin, thats great, yes it is a good puzzle, great to see people using Page Headers this way. Category based styling is fun, taxonomy classes are added to the Article container, if you want them in the body, this may help:

    https://css-tricks.com/snippets/wordpress/add-category-name-body_class/

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.