Support

Account

Home Forums General Issues Add a special global link on top of post title Reply To: Add a special global link on top of post title

  • The problem with filtering the_title is that your sub title will be inside of whatever heading tag the theme is using (h1, h2, h3, whatever)

    
    add_filter('the_title', 'wps_sponsored', 10, 2);
    function wps_sponsored($title, $post_id) {
      $sub_title = get_field('sub-title-field-name', $post_id);
      if ($sub_title) {
        $url = get_field('sub-title-url-field-name, $post_id);
        if ($url) {
          $sub_title = '<a href="'.$url.'">'.$sub_title.'</a>';
        }
        $sub_title = '<span class="subtitle">'.$sub_title.'</span>';
        $title = $sub_title.$title;
      }
      return $title;
    }