Support » Plugin: Advanced Custom Fields » Add a special link on top of post title

  • Hello guys,

    Is it possible to use this plugin to add a special subtitle (that links to another page on my site) on the top of post titles? Here’s an image for illustration;

    The closest I have come to doing this using ACF is through this article on WP Beginner. However, it appends the subtitle on the post title. Also, it doesn’t not include a hyperlink.

    add_filter( 'the_title', 'wps_sponsored' );
    function wps_sponsored( $title ) {
       global $post;
       $sponsored = get_post_meta($post->ID, 'sponsored', true);
       if( is_single() && $sponsored == 'true' ){
           return 'Sponsored post: '.$title;
       return $title;

    Is there a way to modify the code and make it work as per my wish or do you have an idea of how I can achieve what I need?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hi @deewinc,

    there is no problem with what you want to accomplish. But you may need to be familiar with WordPress themes so you can edit them.

    Each theme is very different, so I will give you the “general idea”, so you can find the exact answer for your need.

    – You have to edit the single.php in your Child Theme
    – In that file, before the code that generates the title is, you have to add the ACF code for that custom field
    – In each post, in the WP-admin, you will have a way to fill that field with the URL you want to be linked to
    – If this URL is something global, not different in each post, you can create an Options Page (ACF Pro needed) so you can add there the global URL (or you can add it directly on the single.php file, no ACF Pro needed for that).

    Thread Starter deewinc



    Thanks for your response. It’s a global link for all posts. Any idea how I can achieve that using ACF Pro as mentioned?

    Hi @deewinc,

    I would suggest to:

    – Create an Options Page with ACF Pro
    – Create a text/link field on that Options Page
    – Retrieve that custom field content in the single.php and add it on top of the title
    – Whenever you want to change the URL, just change it on the Options Page

    Extra tips:
    – If you also create a Custom Field for the “text”, you can update text and link from that Options Page.
    – If you also add a True/False field, you can use it as a switch so you can manage if that link is shown or not on the frontend.

    Thread Starter deewinc



    Thanks for your response. I have since done the following and I do have the following questions as well.

    1. Created an options page

    2. Created a link on the options page

    3. Added a True/False field


    1. (Retrieve that custom field content in the single.php and add it on top of the title)< How do I do this?

    • This reply was modified 1 year, 3 months ago by deewinc.
    Thread Starter deewinc


    @ibonazkoitia ~ update. I already know where to add the php code on the post template. However, I don’t know where to extract the php for the ACF’s custom field that I have created.

    Hello @deewinc,

    on the “Options Pages” I shared with you, there is a section called “Template usage”. There you can find the info you need to get that custom field data:

    <?php the_field('header_title', 'option'); ?>

    Just replace ‘header_title’ with your custom field name.

    You also mention that you added a True/False input, then you can use the True/False custom field documentation:

    if( get_field('color') ) {
        // Do something.

    In your case, you should add the “, ‘option'” parameter after the custom field name.

    Did this work for you?

    Thread Starter deewinc


    @ibonazkoitia thanks for your reply. I will give you an update in like an hours time.

    Thread Starter deewinc


    @ibonazkoitia what if the ‘option’ parameter is two words, how should I write it

    <?php the_field('affiliate_disclosure', 'option'); ?>

    I have replaced the header_title with affiliate_disclosure

    The option parameter is AFFILIATE DISCLOSURE (Two words)

    Hi @deewinc,

    when you create a custom field, you have two inputs:

    Field Label = Header Title
    Field Name = header_title

    In your case:

    Field Name = affiliate_disclosure

    The ‘option’ parameter has to remain as it is, it’s just the way ACF searches through the Option Pages (in all the pages you may create now or in the future).

    The Field Label is just used in the backend to know which field you are working with and make it easy to understand.

    The Field Name is used in the frontend/code so you can use it.

    If all these don’t work, you may want to send a couple of screenshots with the Field configuration and the single.php file

    Thread Starter deewinc


    Hello @ibonazkoitia

    Thanks so much for your reply. It did work but the problem is, ACF isn’t displaying the field label on the post.

    Instead, it displays a non-clickable link (the link that I want linked to the affiliate disclosure title) on the top of the post title.

    Hi @deewinc,

    I visited the website and that page post and I see the link working perfectly and linking to the Affiliate Disclosure page.

    Is it solved?

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Add a special link on top of post title’ is closed to new replies.