I have a website with 400+ images. Using a spreadsheet plugin I've been through and manually addedalt
text to each of the images.
The problem I have is that the pages are built with a page builder and a lot of the images where added in text blocks using<img src="https://example.com/image-folder/image-name.jpg">
and therefore haven't dynamically pulled in thealt
text.
I'm trying to avoid having to go through all of the pages, find theimg
code, work out which image it is, look up thealt
text and manually type it, again!
I'm thinking there must be a way to reference the image in the database by theimg
src
, then get thealt
text from the database that way.
I'd like to write a function that sits in the functions file and I can call from thealt
text.
Something like thisget_alt_text()
:
<img src="https://example.com/image-folder/image-name.jpg" alt="<?php echo( get_alt_text() ); ?>">
This way I can just paste in a single bit of text into each imagealt
which would save a ton of time.
It seems there are functions that could help me, but it's a bit more than I fully understand right now and wondered if someone could at least say (with confidence) that it's possible or not.
For example this Wordpress "attachment_url_to_postid" function.
or this "wp_get_attachment_image_src" function
My thinking for the function is:
img
src
alt
text and pass that backSo, my question is:
Thank you for your time.
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.