How to replace a function using a child theme?

I have the following function where I would like to replace the image nopic.jpg

I have updated by deleting some redundant options.

    if ( ! function_exists( 'TaskerDev_get_first_post_image_fnc' ) ) :
            function TaskerDev_get_first_post_image_fnc($pid, $w = 100, $h = 100) {

                //---------------------
                // build the exclude list
                $exclude = array();

                $args = array(
                'order'          = 'ASC',
                'post_type'      = 'attachment',
                'post_parent'    = $pid,
                'meta_key'       = 'another_reserved1',
                'meta_value'     = '1',
                'numberposts'    = -1,
                'post_status'    = null,
                );
                $attachments = get_posts($args);
                if ($attachments) {
                        foreach ($attachments as $attachment) {
                        $url = $attachment-ID;
                        array_push($exclude, $url);
                    }
                }

                //-----------------

                $args = array(
                'order'          = 'ASC',
                'orderby'        = 'post_date',
                'post_type'      = 'attachment',
                'post_parent'    = $pid,
                'exclude'           = $exclude,
                'post_mime_type' = 'image',
                'post_status'    = null,
                'numberposts'    = 1,
                );
                $attachments = get_posts($args);
                if ($attachments) {
                    foreach ($attachments as $attachment) {
                        //$url = wp_get_attachment_url($attachment-ID);
                        return TaskerDev_wp_get_attachment_image($attachment-ID, 'thumb_image_thing');
                    }
                }
                #else   return get_bloginfo('template_url').'/images/nopic.jpg';
                else    return get_stylesheet_directory_uri().'/images/Picture16.jpg';
            }
            /*************************************************************
            //*
            *   TaskerDev (c) sitemile.com - function
            /
            *************************************************************/
        endif;

When done, everything works fine for about an hour and then I get the following error:

the function TaskerDev_get_first_post_image_fnc() cannot be called twice, it's been called in the parent already (just paragraphing what it says)

What is the most efficient way to update the image by been able to called it within the child theme. IS there a short hook or action maybe? Thanks.

Topic wp-api function-exists actions wp-head hooks Wordpress

Category Web


You should wrap your function in parent theme like this, not in child theme function.php

if (!function_exists('TaskerDev_get_first_post_image_fnc') ){
function TaskerDev_get_first_post_image_fnc($pid, $w = 100, $h = 100)
    {
//Parent theme code here
 }
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.