• Resolved tpinkus

    (@tpinkus)


    Hello ??

    So I’m looking to add the following filter to add a default frontpage image:

    add_filter('og_og_image_value', 'my_og_og_image_value');
    function my_og_og_image_value($images)
    {
        if ( empty($images) ) {
            $images[] = 'https://wordpress/wp-content/uploads/2014/11/DSCN0570.jpg';
        }
        return $images;
    }

    However, I run a MultiSite install with several sites needing a different default image. Is it possible to pull insert additional PHP to pull their logo? Here is how the HEADER.PHP currently pulls the site logo:

    <?php themename_logo(); ?>

    Thanks for your help ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Marcin Pietrzak

    (@iworks)

    hi @tpinkus

    I’m sorry but

    
    themename_logo();
    

    Is not a standard WordPress function.

    Marcin

    Thread Starter tpinkus

    (@tpinkus)

    This is the code for the filter I’m using

    
    /**  Set Default Open Graph Img to Logo on Frontpage
    ****************************************************/
    
    add_filter('og_og_image_value', 'my_og_og_image_value');
    function my_og_og_image_value($images)
    {
        if ( empty($images) ) {
            $images[] = 'https://grab.new.news.mydailystrip.com/wp-content/uploads/sites/3/korn_189002984-2.jpg';
        }
        return $images;
    }

    And its not working. I don’t believe I’ve done anything wrong. Thoughts?

    Here is the URL: https://kirq-f2.lor.vipology.com/

    Plugin Author Marcin Pietrzak

    (@iworks)

    hi @tpinkus

    Could you change it for this:

    
    function my_og_og_image_value($images)
    {
        if ( empty($images) ) {
            return array( 'https://grab.new.news.mydailystrip.com/wp-content/uploads/sites/3/korn_189002984-2.jpg' );
        }
        return $images;
    }
    

    empty($images) is true for null too, and $images[] on null will be not working.

    Marcin

    Thread Starter tpinkus

    (@tpinkus)

    This is what I went with and it works flawlessly

    /**  Set Default OpenGraph Image on Frontpage
    ****************************************************/
    
        add_filter('og_image_init', 'my_og_image_init');
        function my_og_image_init($images)
        {
            if ( is_front_page() || is_home() ) {
                $images[] = theme_get_option( 'social_image_url' );
            }
            return $images;
        }

    The “social_image_url” is a theme option I added to allow them to set the default image to whatever they want.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Default Front Page image’ is closed to new replies.