1

I'm using a function to separate Featured Content.

What I mean is that: if I selected format Gallery will show the First Gallery in my post , if I choose format Video , will show a video instead .

this is the function:

//Get Featured Media depending on Format
if (!function_exists('get_featured_media')):
    function get_featured_media()
    {
        global $post, $prefix;
        $image = get_the_post_thumbnail($post->ID, 'dreams-640x360', array('class' => "lazyload"));
        $image_caption = esc_html(get_the_post_thumbnail_caption());

        $gallery = get_post_gallery($post->ID, false);
        //$gallery_img_caption = esc_html(the_title());

        $video = get_post_meta($post->ID, "{$prefix}videos_oembed", true);
        $oembed_code = wp_oembed_get($video);

        $getMedia = '';



        if (has_post_format('gallery')) {

            if (get_post_gallery()) {

                $getMedia .= "<figure class=\"f4_article-info__meta--gallery\">";

                foreach ($gallery['src'] as $src) {
                    $getMedia .= "<img src=\"$src\" class=\"my-custom-class\" alt=\"$gallery_img_caption\" />";
                }
            } else {
                if (has_post_thumbnail($post->ID)) {
                    $getMedia .= "<figure class=\"f4_article-info__meta--gallery\">";
                    $getMedia .= "$image";
                    $getMedia .= "$image_caption";
                }
            }

        } elseif (has_post_format('video')) {

            if ($video) {
                $getMedia .= "<figure class=\"f4_article-info__meta--video\">";
                $getMedia .= "$oembed_code";
            } else {
                if (has_post_thumbnail($post->ID)) {
                    $getMedia .= "<figure class=\"f4_article-info__meta--video\">";
                    $getMedia .= "$image";
                    $getMedia .= "$image_caption";
                }
            }

        } else {
            if (has_post_thumbnail($post->ID)) {
                $getMedia .= "<figure class=\"f4_article-info__meta--image\">";
                $getMedia .= "$image";
                $getMedia .= "$image_caption";
            }
        }

        if (!empty($getMedia)) {
            $getMedia = "\n<!-- Featured Media -->\n" . $getMedia . "\n</figure>";
            echo $getMedia;
        }

    }
endif;

Now Format Gallery will work using the first gallery created in our post.

With this idea , I would like to hide the first gallery inside the_content()

The obvious approach is to hide it via CSS (http://codepen.io/DreamsEngine/pen/BpPLXg) , but that that will be rendered by DOM isn't ? , and what everyone is looking is performance...

What do you recommend for this?

1
  • I would sure like to know the answer to this too...
    – Ralphonz
    Jul 19, 2017 at 21:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.