Support » Themes and Templates » Displaying “alt” attribute text as captions?

  • We are moving a large newspaper website from Drupal to WordPress and my last coding tweak involves displaying the legacy caption information from images in article posts. The caption information is included in “alt” and “title” attributes in the HTML for these images, so I basically need to display this info in the template for article posts. Any suggestions on how to set this up? Here is some sample code from an image in an article: <img src="/directory/image/00%202016%20NEWS%20PHOTOS/12%20December/match%20race%20waterfront.jpg" alt="Boats dash past the Charlotte Amalie waterfront during Sunday's CAMR action. (Photo provided by the Carlos Aguilar Match Race)" title="Boats dash past the Charlotte Amalie waterfront during Sunday's CAMR action. (Photo provided by the Carlos Aguilar Match Race)" width="280" vspace="4" hspace="8" height="187" border="1" align="left" />

    What we want to do is display that text from the “alt” or “title” attributes as captions under the images. This needs to be set up for 100,000 legacy article posts on the sites.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi chuck0,

    So, am I correct in understanding that you need a way to pull the content from the <alt> tags on your Drupal install and feed it into the caption field in your new WordPress database?

    No. All of the content from the old Drupal site has been migrated to a WordPress multisite install. So what we have is old content that was marked up in the old system, which is now a post (story//article) on the new sites. Most of the stories have images which contain the captions as attributes of the img code. See the above code for an example.

    The old Drupal site was coded to display captions from images based on the text string set in the “alt” or “text” string in each image’s HTML code.

    What I’m looking for is a solution for displaying that attribute text as a caption under the image with that code. So if the code for an image in the story has an alt attribute string of “Boats dash past the Charlotte Amalie waterfront…”, that text string would be displayed under that image. Something tells me this needs to involve functions.php and the single page template.

    Thanks!

    Hi chuck0,

    Ah, okay. With you now. You’re getting beyond my scope of knowledge and comfort but let me see if I can’t offer an idea of value.

    If the images sit within the media library and the alt content (“Boats dash past …”) sits within the alt field in the media library, then it should be feasible to write code that pulls the content of that alt field from the image within the media library. A conditional along the lines of “if an image has ‘alt’ content, then display ‘alt’ content”.

    I appreciate my reply doesn’t give you any code, and frankly, I am not one to know the code, but perhaps my answer was of some value.

    Interesting to know, thank you.

    Thanks, Liam, for your thoughts on my question!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Displaying “alt” attribute text as captions?’ is closed to new replies.