Overriding a WordPress parent function that isn’t tied to any actions

I have a parent theme function as follows:

/*-----------------------------------------------------------------------------------*/
/* Display first image linked portfolio */
/*-----------------------------------------------------------------------------------*/

function ct_first_image_linked_portfolio() {
    $photo = ct_get_post_image();
    global $ct_options;
    global $post; ?>
    <figure>
        <div><?php the_post_thumbnail('large'); ?></div>
        <figcaption>
            <h3 class="marB0"><?php the_title(); ?></h3>
            <span><?php the_author(); ?></span>
            <a href="<?php the_permalink() ?>">View</a>
        </figcaption>
    </figure>
<?php }

I want to edit the markup that this function outputs. At first I thought I’d need to utilise some actions/filters to somehow filter the output. On closer inspection, the function doesn’t seem to be tied to any actions, and is simply called directly from a template file loop-portfolio.php:

Read More
while ( $query->have_posts() ) : $query->the_post(); ?>

    <li class="<?php ct_first_term(); ?> item col span_4">
        <?php ct_first_image_linked_portfolio(); ?>
    </li>   

<?php endwhile; ?>

So my question is, do I simply duplicate loop-portfolio.php into my child theme, and then change the function call to a different function? It seems like it would work but I’m checking there’s not a better way to do this. Thanks.

Related posts

Leave a Reply

1 comment

  1. If the parent function doesn’t offer any filter hook to change the markup nor is encapsulated inside an if(!function_exists(FUNC)) {} (known as pluggable function), then yes, child theme + new function is the way to go.