• Resolved ssdesign1

    (@ssdesign1)


    I’m using pods custom fields and beaver builder theme and page builder. I’m struggling to add the alt text to my custom image.

    [pods field='image_1.alt_text']

    My custom field is called image_1
    The alt text comes up blank in the source code.

    Thanks in advance!

Viewing 15 replies - 1 through 15 (of 15 total)
  • If you did

    [pods field='image_1._img']

    It would generate the whole image tag for you with the alt text etc ??

    Thread Starter ssdesign1

    (@ssdesign1)

    Thanks for your help! I’m getting a broken link when I add the ._img though.
    This is my code.. am I missing something?

    [pods field=’image_1._img’]

    • This reply was modified 2 years, 2 months ago by ssdesign1.
    • This reply was modified 2 years, 2 months ago by ssdesign1.
    Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    Is the field image_1 a file field in Pods? What kind of broken link do you see?

    Thread Starter ssdesign1

    (@ssdesign1)

    It’s a file/image/video field. The code was working without the ._img ending. The image is missing with a broken image graphic. here is my code:

    <div class="fl-post-image">
       
        <a href="[wpbb post:url]" >
        	<img src=" [pods field='image_1._img']"></a>
    </div>

    You don’t need the image tag at all as the _img generates the image tag for you and it will use the alt tag you have set in the media library ??

    Please try changing your code to this:

    
    <div class="fl-post-image">
       
        <a href="[wpbb post:url]" >
        	[pods field='image_1._img']
     </a>
    </div>
    
    • This reply was modified 2 years, 2 months ago by Jamie.
    • This reply was modified 2 years, 2 months ago by Jamie.
    • This reply was modified 2 years, 2 months ago by Jamie.
    • This reply was modified 2 years, 2 months ago by Jamie.
    • This reply was modified 2 years, 2 months ago by Jamie. Reason: code editing when editing a post sucks
    • This reply was modified 2 years, 2 months ago by Jamie.
    Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    If you do need to customize the image tag for some reason, you can always use the ._src variation instead of ._img

    Thread Starter ssdesign1

    (@ssdesign1)

    Thank you so much! I appreciate your time!!

    Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    We are always happy to help, it’s what we love!

    If I need the alt-text separately, forget src, forget the tag, just the alt-text. Is there something like this:

    field='image_1._alt'

    In php I could also use:

    $alt_text = get_post_meta($image_id , '_wp_attachment_image_alt', true);

    But I’d still need the help of Pods to know the value of $image_id.

    Is there something like this:

    field='image_1._id'

    The question is, can Pods in any way spare me from having to query the database in order to get the alt-text?

    Plugin Support Paul Clark

    (@pdclark)

    @cncup [pods][each image_1]{@_wp_attachment_image_alt}[/each][/pods]

    Plugin Support Paul Clark

    (@pdclark)

    @cncup Or [pods]{@image_1._wp_attachment_image_alt}[/pods]

    Plugin Support Paul Clark

    (@pdclark)

    @cncup Or [pods field="image_1._wp_attachment_image_alt"][/pods]

    Thanks for the quick reply, Paul. This is perfect.

    I needed it in php actually, so just for future reference if someone finds it helpful, it looks like this:

    $pod = pods( 'my_cpt_name', get_the_ID() );
    $alt_text = $pod->field( 'image_1._wp_attachment_image_alt' );

    Many thanks!

    Plugin Support Paul Clark

    (@pdclark)

    Great. One more method, using WP core functions in PHP:

    $alt_text = get_post_meta(
    	(int) get_post_meta(
    		get_the_ID(),
    		'image_1',
    		true
    	),
    	'_wp_attachment_image_alt',
    	true
    );

    Or on one line:

    $alt_text = get_post_meta( (int) get_post_meta( get_the_ID(), 'image_1', true ), '_wp_attachment_image_alt', true );

    Oh, very good to know. Appreciated!

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘adding alt text to a pods custom img in beaver builder’ is closed to new replies.