Title: Inserting the_title() into a function?
Last modified: August 19, 2016

---

# Inserting the_title() into a function?

 *  Resolved [apaimagixdk](https://wordpress.org/support/users/apaimagixdk/)
 * (@apaimagixdk)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/inserting-the_title-into-a-function/)
 * Hi,
 * I want to automaticly insert the current post title into this line where it says
   PRODUCT-NAME… (in single.php)
 * `<?php echo print_wp_cart_button_for_product(’PRODUCT-NAME’, PRODUCT-PRICE); ?
   >`
 * It’s probably simple but i am no good with php.
 * Hope somebody can help me?
 * Regards,
    Anders

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/inserting-the_title-into-a-function/#post-1059318)
 * Should be able to replace ‘PRODUCT-NAME’ with $post->post_title as long as that
   code is in a [post loop](http://codex.wordpress.org/The_Loop).
 *  Thread Starter [apaimagixdk](https://wordpress.org/support/users/apaimagixdk/)
 * (@apaimagixdk)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/inserting-the_title-into-a-function/#post-1059385)
 * It works. Thanks! You dont want to know how much time i spent trying to figure
   it out by myself!
 *  [syncbox](https://wordpress.org/support/users/syncbox/)
 * (@syncbox)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/inserting-the_title-into-a-function/#post-1059542)
 * This is a variation on that question, but definitely related… in the same cart
   plugin, how could you get the data from a custom field that contains the product
   name and price into the cart button template code? For example, the cart uses:
 * <?php echo print_wp_cart_button_for_product(‘PRODUCT-NAME’, PRODUCT-PRICE); ?
   >
 * and the info I want is stored in custom field keys “MMTname” and “MMTprice”….
   I am already displaying this data (and more) from custom fields in the same page.
 * Help greatly appreciated!
 *  [syncbox](https://wordpress.org/support/users/syncbox/)
 * (@syncbox)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/inserting-the_title-into-a-function/#post-1059543)
 * Nevermind… going on what was suggested above, I put the custom field data into
   $vars like:
 *     ```
       $prodname = c2c_get_custom('MMTname');
       $prodprice = c2c_get_custom('MMTprice');
       ```
   
 * and then later, when calling the cart button, used them, like so:
 * `<?php echo print_wp_cart_button_for_product($prodname, $prodprice); ?>`
 * Thanks for pointing me in the right direction!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Inserting the_title() into a function?’ is closed to new replies.

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)

 * 4 replies
 * 3 participants
 * Last reply from: [syncbox](https://wordpress.org/support/users/syncbox/)
 * Last activity: [16 years, 7 months ago](https://wordpress.org/support/topic/inserting-the_title-into-a-function/#post-1059543)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
