How to use “Get The Image” plugin to work with headway

Before diving in let me clarify one thing.

What is a featured image or a Post Thumbnail?

Featured Image or Post Thumbnail is an image  that is set  to represent a Posts, Pages or Custom Post Types.

featured-imageIt is not long time ago when I developed a site for a client of mine that has tones of post of it. The previous theme uses a plugin called “Get the Image“, what it does is that it pulls the first image in the post and set it as featured image. While the actual post itself does not have a featured image set on it on the back end,  the front-end does have it, this is where the plugin gets into work.

Working with headway, setting a featured post was really an easy task using the Visual Editor, it is just a tick on a contents block from the grid mode, but this only works if the actual post itself has a featured image on it. Everything can be resolved easily if I will just add the featured image manually, this should be an easy task only if you got a couple of post in it, but what if you have thousands of it, what will you do?

Although there are a couple of good plugins to automate the job, i decided not to use it, mainly because I want to maintain the integrity of the site structure, and also to warn that this is not reversible, you cannot undo the process, another plugin would do to automate it (i don’t know if a plugin to remove featured image does exist, i haven’t done a search for it), also adding a featured image on every post will surely increase the database size considering there are more than 6000 post on it. So I decided and dig deeper on how I can integrate the “Get the image” plugin to do the work for me.

It turns out that the couple of hours work only needs a few lines of code to accomplish.

So here is the simple process:

  1. Uncheck the “Show Featured Image” in your content block options in the grid mode of visual editor.
    show-featured-image
  2. Add this code to your headway child theme.
    //Integrate Get The Image Plugin
      add_action('headway_before_entry_content','my_excerpt');
        function my_excerpt(){
            global $post;
    
            if (is_home() || is_front_page()) {
                if ( function_exists( 'get_the_image' ) ) {
                    if( get_post_meta($post->ID, "featuredthumb", true) ):
                        get_the_image( array( 'meta_key' => 'post-thumbnail', 'size' => 'full' ) );
                    else:
                        get_the_image( array( 'order_of_image' => 2, 'image_scan' => true, 
                        'meta_key' => array( 'featuredImg' ), 'size' => 'full' ) );
                    endif;
                }
            }
    
        return true;
      }
    

That is it. Congratulations.

See the code in action here

One Response to How to use “Get The Image” plugin to work with headway

Leave a reply

Book your free consultation
Share This