Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 286 Vote(s) - 3.65 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Add custom classes to "wp_get_attachment_image( $attachment_id)" wordpress function

#1
I can get images using wp_get_attachment_image($attachment_id) wordpress function.It automatically add below code.

<img width="150" height="150" src="http://localhost/test2/wordpress/wp-content/uploads/2019/08/pexels-photo-1308624-150x150.jpeg" class="attachment-thumbnail size-thumbnail" alt="">

I want to add "alt" and another class using this function. To be specific I want to generate code like this.

<img width="150" height="150" src="http://localhost/test2/wordpress/wp-content/uploads/2019/08/pexels-photo-1308624-150x150.jpeg" class="attachment-thumbnail size-thumbnail custom-class" alt="Some Alt Value">
Reply

#2
You can pass it like this.

<?php echo wp_get_attachment_image( $attachment_id, 'thumbnail', "", ["class" => "my-custom-class","alt"=>"some"]); ?>

You can read the full documentation here.

[To see links please register here]

Reply

#3
You can pass mulitple attributes, for a custom class you can do:

<?php echo wp_get_attachment_image($image_id, 'full', false, array('class' => 'my-custom-class')); ?>
Reply

#4
Pretty sure someone else will bump on this; the classes can be space separated so that multiple classes can be added.

```php
<?php
echo wp_get_attachment_image($image_id, 'full', false,
array('class' => 'my-custom-class class2 class3'));
?>
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through