0

Usually I would get a post title no problem, however now I need to achieve something like this:

The Example is written for this title

As you can see two words are links in the title, another problem is that there could be any number of links, as it will depend on a content. How can I achieve this? will I have to use additional fields in WordPress? how to show WordPress which words in the title are links? And in addition, I will need to somehow store url for the link.

5
  • 1
    Can I ask why? This sounds problematic from a UI/UX point of view
    – Tom J Nowell
    Apr 19, 2013 at 15:18
  • @TomJNowell Title will essentially be song name with artist / artists in it. I want to make artist names links to their twitter / facebook profiles.
    – Ilja
    Apr 19, 2013 at 17:32
  • So then could you not automatically generate titles rather than attempt to do a the_title call? Turning the title box into a full blow tinyMCE instance is not a solution to your problem it's a kludge and that's where you seem to be headed
    – Tom J Nowell
    Apr 20, 2013 at 18:33
  • @TomJNowell perhaps, I'm still new to wordpress and would like to achieve this in best possible way. Could you by any chance expand on the idea of automatically generating titles?
    – Ilja
    Apr 20, 2013 at 20:37
  • Instead of calling the_title, you'd just echo one out at runtime inside h1 tags. nothing unusual about it really, have post meta specifying the artist etc and then use that. The specifics of how are very dependent on how your storing your data etc, so I wont go into it as that would be off topic
    – Tom J Nowell
    Apr 20, 2013 at 22:03

2 Answers 2

1

The easy way of doing this is to not display the title on your page template, and have a h1 header as the first thing in your content.

0

Agreed with Tom on this being a questionable UI/UX practice, but here's some code for educational purposes (it goes into your theme's functions.php):

add_filter( 'the_title', 'wpse0419_modified_post_title');
function wpse0419_modified_post_title ($title,$id) { 
    if ( $id == get_the_ID() ) { // narrow down to current item's title only
        $meta_url = get_post_meta($id, 'your_meta_key_url', true);
        if($meta_url){
            $title = $title . "(<a href='" . $meta_url ."'>modified title</a>)";
        }
    }
    return $title;
}

You can read up on filters in this Codex article, and about storing custom variables in post meta in this one.

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.