Generic Image Call in Functions

  • jrothra


    This question is mostly due to my lack of knowledge of php. In the slider I want to use a different generic image. I see that it’s called in the parent theme’s functions.php file. I also know I need to edit that in the child’s functions.php file. However, do I need to put ALL of this code in the child theme?

    if (!function_exists('graphene_get_post_image')) :
    function graphene_get_post_image($post_id = NULL, $size = 'thumbnail', $context = '', $urlonly = false){

    /* Display error message if no post ID is supplied */
    if ($post_id == NULL){
    _e('<strong>ERROR: You must supply the post ID to get the image from as an argument when calling the graphene_get_post_image() function.</strong>', 'graphene');

    /* Get the images */
    $images = get_children(array(
    'post_type' => 'attachment',
    'post_mime_type' => 'image',
    'post_parent' => $post_id,
    'orderby' => 'menu_order',
    'order' => 'ASC',
    'numberposts' => 1,
    ), ARRAY_A);

    $html = '';

    /* Returns generic image if there is no image to show */
    if (empty($images) && $context != 'excerpt' && !$urlonly) {
    $html .= apply_filters('graphene_generic_slider_img', '<img alt="" src="'.get_template_directory_uri().'/images/img_slider_generic.png" />');

    /* Build the <img> tag if there is an image */
    foreach ($images as $image){
    if (!$urlonly) {
    if ($context == 'excerpt') {$html .= '<div class="excerpt-thumb">';};
    $html .= '<a href="'.get_permalink($post_id).'">';
    $html .= wp_get_attachment_image($image['ID'], $size);
    $html .= '</a>';
    if ($context == 'excerpt') {$html .= '</div>';};
    } else {
    $html = wp_get_attachment_image_src($image['ID'], $size);

    /* Returns the image HTMl */
    return $html;

    I want to call a different image from the child theme’s image folder, changing this:


    to this image instead:


    By the way, I tried adding only this part to the child’s file, but it didn’t work:

    /* Returns generic image if there is no image to show */
    if (empty($images) && $context != 'excerpt' && !$urlonly) {
    $html .= apply_filters('graphene_generic_slider_img', '<img alt="" src="'.get_template_directory_uri().'" />');

    All I got was this error when I tried saving the functions.php file:

    Warning: Cannot modify header information – headers already sent by (output started at /home/gcgop/public_html/wp-content/themes/graphene-child/functions.php:40) in /home/gcgop/public_html/wp-admin/theme-editor.php on line 99



    Related issue: I just tried updating the CSS file in the child theme, and all I get is the error quoted above. Odd.


    Syahir Hakim


    That error is usually caused by the mentioned file outputting a character when it isn’t supposed to. Check your child theme’s functions.php file to see if you have an extra space between the opening <?php and closing ?> tags at or about line 40.

    To change the generic image, just add this in your child theme’s functions.php file:

    function graphene_custom_generic_img(){
    return '<img alt="" src="'.get_stylesheet_directory_uri().'/images/img_slider_generic-GCGOP.png" />';
    add_filter( 'graphene_generic_slider_img', 'graphene_custom_generic_img' );



    The extra space was it! I never thought that would cause such trouble. Also, thank you for all your help. 🙂

Viewing 4 posts - 1 through 4 (of 4 total)

  • You must be logged in to reply to this topic.