WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm customizing a custom theme to use WooCommerce. One of the issues I've run into is adding a span tag around a product title on the single product page. I've figured out how to add a filter to the the_title method but unfortunately that method is used in other places like in the product image alt tag (which breaks it).

Is there a way to specify to only modify the_title when it is printing the main title to the page instead of being used elsewhere like an image attribute?

Here's what I have so far:

function my_product_title($title, $id)
    if(in_the_loop() && is_product())
        return '<span class="border">FooBar</span>';
    return $title;
add_filter( 'the_title', 'my_product_title', 5, 2);

Shouldn't there be a way to hook up to the woocommerce_product_title filter? I've tried to do so unsuccesfully.

In the mean time I know I can modify the single-product/title.php template file but I would rather achieve this with actions or filters.

share|improve this question

closed as off-topic by Pieter Goosen, gmazzap, cybmeta, kaiser Nov 22 '14 at 8:34

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 3 down vote accepted

Here is how you do it,

First remove woocommerce single title action, and create your own function to handle the title, later add back the action using your newly created function.


add_action('woocommerce_single_product_summary', 'woocommerce_my_single_title',5);

if ( ! function_exists( 'woocommerce_my_single_title' ) ) {
   function woocommerce_my_single_title() {
            <h1 itemprop="name" class="product_title entry-title"><span><?php the_title(); ?></span></h1>

share|improve this answer
-1 Answering off topic questions – Brad Dalton Nov 20 '14 at 20:46

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