Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using the Headway theme, and I need to add custom field code to page & posttitles. This is what I need to be able to do. example

The red button will be added through a custom field. It needs to be shown inline with the title. I have worked out I can do this using the headway_after_entry_title hook, but I can't seem to get the code right to retrieve the custom fields. I got this far :

//Add custom field image after entry title 
function title_btn() {
    echo '<div class="title-btn">[custom field code to go here]</div>';
} 
add_action('headway_after_entry_title', 'title_btn');

and the outcome should be:

<a href="xxx"><img src="xxx"></a> 

where the xxx is the custom field url code

Hope anybody can help me out with this.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

There's the get_post_meta() function to retrieve those data.

So basically, you'd write a function in your functions.php file (or in a custom plugin - take "Hello Dolly" as example) and hook it.

<?php
/* Plugin Name: (#66495) »kaiser« Headway Title Button */
function wpse66495_headway_title_button()
{
    return printf(
         '<div class="title-btn"><a href="%s" alt="%s"><img src="%s /></a></div>'
        ,get_post_meta( get_the_ID(), 'meta_key_link_url', true )
        ,get_the_title()
        ,get_post_meta( get_the_ID(), 'meta_key_thumb_url', true )
    );
}
add_action( 'headway_after_entry_title', 'wpse66495_headway_title_button' );
share|improve this answer
    
how can I get my custom fields in here like this: <a href="customfield1"><img src="customfield2"></a> both customfields are urls –  Marja Sep 28 '12 at 11:36
    
See Update and read the code. You'll see where to enter those meta keys. –  kaiser Sep 28 '12 at 12:42
    
Thanks so much for this! would it be possible to edit this function so it won't show if the fields are empty? At the moment it takes up a lot of blank space. –  Marja Sep 28 '12 at 15:55
    
Check all the isset(), empty(), etc. stuff on php.net –  kaiser Sep 28 '12 at 23:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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