Create custom function for hero image


I’m newbies with php development and I want create a custom functions

I would like to create a function that calls an image which has the same name as the product but I fail to call the product name and then place it in the image name. Could you help me please.

my code :

add_action('init', 'custom_hero_image');
function custom_hero_image() {
    $result = get_the_title( 'ID' );
    if ( is_product() ) {
        $html .= '<img class="jarallax-img" src="'. get_template_directory_uri() .'/inc/assets/img/shop/hero/'.$result.'.jpg">';
    } else {
        $html = '<p>No results found.</p>';
    return $html;

What I’m doing wrong?

GilbertOOl 2 years 2020-12-15T23:10:27-05:00 0 Answers 5 views 0

Leave an answer