• Resolved boborg

    (@boborg)


    I am trying to add a custom image to a custom post type archive. I have found the code below on the web but if I add it to my theme functions.php my site does not work anymore HTTP 500 error. Any ideas?

    add_filter(‘wpseo_opengraph_image’, ‘cpt-archive-image’, 10, 1);
    function cpt-archive-image($og_image) {
    if( is_post_type_archive(‘my_cpt’) )
    $og_image = ‘https://www.example.com/my-image.jpg’;

    return $og_image;
    };

Viewing 2 replies - 1 through 2 (of 2 total)
  • add_filter(‘wpseo_opengraph_image’, ‘cpt-archive-image’, 10, 1);
    function cpt-archive-image($og_image) {
    if( is_post_type_archive(‘my_cpt’) ) {
    $og_image = ‘https://www.example.com/my-image.jpg’;
    }
    return $og_image;
    };

    You missed the { } in the if statement

    • This reply was modified 8 years, 1 month ago by lofesa.
    Thread Starter boborg

    (@boborg)

    Yes and cpt-archive-image should be cpt_archive_image

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding og:image to custom post type archive?’ is closed to new replies.