Comments (9)
This would be nice to have. Besides the obvious reason to add this, I can see organizations requiring alt text on all relevant images due to government accessibility regulations.
from magic-fields-2.
It will be also "SEO useful" too. Let's have a try
from magic-fields-2.
+1
from magic-fields-2.
When we will know if it this request is implemented? :D
from magic-fields-2.
I'm using the get_image function() with the $tag_img param on zero(false) with a label field on alt and title attributes.
<img title="<?php echo get('my_label'); ?>" alt="<?php echo get('my_label'); ?>" src="<?php echo get_image('my_imagem',1,1,0); ?>" />
from magic-fields-2.
Sure this is the "standard" way but It would be really better having a "combo" field like drupal. It would be easier.
from magic-fields-2.
There are alt and caption fields in WP's Media Library. Ideally, there should be a way to pull these fields directly from the get_image function, but barring that, there should at the very least be a way to return the image's ID so we can manually retrieve these fields.
from magic-fields-2.
Add this to functions.php
function get_alt( $attachment_url = '' ) {
global $wpdb;
$attachment_id = false;
// If there is no url, return.
if ( '' == $attachment_url )
return;
// Get the upload directory paths
$upload_dir_paths = wp_upload_dir();
// Make sure the upload path base directory exists in the attachment URL, to verify that we're working with a media library image
if ( false !== strpos( $attachment_url, $upload_dir_paths['baseurl'] ) ) {
// If this is the URL of an auto-generated thumbnail, get the URL of the original image
$attachment_url = preg_replace( '/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i', '', $attachment_url );
// Remove the upload path base directory from the attachment URL
$attachment_url = str_replace( $upload_dir_paths['baseurl'] . '/', '', $attachment_url );
// Finally, run a custom database query to get the attachment ID from the modified attachment URL
$attachment_id = $wpdb->get_var( $wpdb->prepare( "SELECT wposts.ID FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = '_wp_attached_file' AND wpostmeta.meta_value = '%s' AND wposts.post_type = 'attachment'", $attachment_url ) );
}
// get the alt text
$alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
// return alt
return $alt;
}
Usage
$img = get('the_img');
echo get_alt($img);
from magic-fields-2.
I'm cleaning the issues if you still have this problem reopen the issue. thanks
from magic-fields-2.
Related Issues (20)
- Url convert to relative url HOT 16
- display or not :) `? HOT 1
- Image Issues (both Image Media and Image Upload)
- Issue in required type of custom field "File" HOT 1
- Error
- Custom fields looks empty HOT 1
- Causing HTTP ERROR 500 on wp-admin HOT 1
- Plugin version in plugin folder name it's bad distribution approach
- Browser alert on every post saving
- Recoverable fatal error HOT 4
- When performing a full site export mappings do not persist
- Image from media not attaching to post
- Webshell Threat Found
- Problem with MF v2.3.3.1 and S3offload HOT 1
- Is this project active?
- plugin conflict
- Magic Fields data is not being saved HOT 1
- Date Picker not working with Wordpress 5.5 Update HOT 2
- Broken after Wordpress 5.4.4 HOT 2
- Estou postando ele salva mais não exibe nada no site
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from magic-fields-2.