0

When a single product is viewed, it would show the title, description of the product, etc.

So what I am trying to do is, to implement a hook for the woocommerce_page_title (got it from here), so that I could prepend the html code for the logo in that text.

But it seems to be not working. The code I have tried is as follows:

add_filter('woocommerce_page_title',
'isa_product_title_heading');

function isa_product_title_heading($content) {
    $abctemp = '<img src="'.home_url('/wp-content/uploads/2013/12/mysite_logo.400_jpg.jpg').'" />' . $content;
    //echo $abctemp; die;
    return __($abctemp, 'woocommerce');
}

enter image description here

In this figure, the yellow portion is where I am trying to insert the logo.

1 Answer 1

0

You can add any image or text to the template directly or using wordpress hooks.

  1. Template way: Create this file structure in your wordpress template foler:

    |
    L templatename
      L woocommerce
        L single-product
          L title.php
    

Insert this code to the title.php:

<?php
/**
 * Single Product title
 */

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

?>
<h1 itemprop="name" class="product_title entry-title">
    <img src="your_image.jpg">
    <?php the_title(); ?>
</h1>

2.The second way is to use this code sample somewhere in your functions.php or in your plugin

    remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_title', 5);
    add_action('woocommerce_single_product_summary', 'custom_template_single_title', 5);
    function custom_template_single_title() {
        global $product;
        echo '<h1 itemprop="name" class="product_title entry-title">'
             . '<img src="your_image.jpg">' 
             . $product->get_title() 
             . '</h1>';
    }

I'd reccomend to use the first way. But if you're developing a plugin, of course, you shouldn't edit templates anyway

1
  • Thanks a bunch. I used the second method and it worked flawlessly. :) Jan 5, 2014 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.