GithubHelp home page GithubHelp logo

Comments (9)

cmwelsh avatar cmwelsh commented on September 25, 2024

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.

gleenk avatar gleenk commented on September 25, 2024

It will be also "SEO useful" too. Let's have a try

from magic-fields-2.

Dermotholmes avatar Dermotholmes commented on September 25, 2024

+1

from magic-fields-2.

gleenk avatar gleenk commented on September 25, 2024

When we will know if it this request is implemented? :D

from magic-fields-2.

leocaseiro avatar leocaseiro commented on September 25, 2024

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.

gleenk avatar gleenk commented on September 25, 2024

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.

JeffreyPia avatar JeffreyPia commented on September 25, 2024

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.

panarican avatar panarican commented on September 25, 2024

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.

hunk avatar hunk commented on September 25, 2024

I'm cleaning the issues if you still have this problem reopen the issue. thanks

from magic-fields-2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.