Site logo

Archived topic

How To Create Feature (Similar to Feature Image)

3 replies · Started by Maggie on May 16, 2022

Viewing posts 1–4 of 4

Hi Team,

How to create Feature Similar to Feature Image using element, this feature is for embeded maps code what to put are the code of wpgmaps.com

Example of code: [wpgmza id="140"]
Link: https://headquartersoffice.com/wsp/

Please educate me on this. Thank you.

Hi there,

you could use a WordPress Custom Field to store your 'code':

1. Edit a post where you want this applied, and in the Options ( 3 dot menu ) -> Preferences --> Panels enable the Custom Fields.

2. Now at the foot of the editor you can Create a New Custom Field.
Give you field a Name eg. wpgmap
And add the code to the Value field: [wpgmza id="140"]

3. Now each time you create a post where you want to add this custom field you will be able to select wpgmap from the list and give it a value.

4. With the value stored we can now output that shortcode using a PHP Snippet:

add_action('generate_after_entry_header', function(){
    $wpgmap = get_post_meta( get_the_id(), 'wpgmap', true );
    if ( $wpgmap && is_single() ) {
        echo do_shortcode( $wpgmap );
    }
});

This will display it on the single post after the Entry header.

Adding PHP: https://docs.generatepress.com/article/adding-php/

Hi, what should i choose to Create a New Custom Field? Thanks.

This archived topic is closed to new replies.