Passer la navigation

[Résolu] How to manage nested quotes when adding shortcodes in alt text attribute

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
How to display user avatar image with alt text attribute

Solution:
To set alt text using custom attribute you can write the custom shortcode.

You can find proposed solution in this case with the following reply:
https://toolset.com/forums/topic/how-to-manage-nested-quotes-when-adding-shortcodes-in-alt-text-attribute/#post-2291921
Relevant Documentation:

This support ticket is created Il y a 4 years, 6 months. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Fuseau horaire du supporter : Asia/Kolkata (GMT+05:30)

Ce sujet contient 6 réponses, a 2 voix.

Dernière mise à jour par dominiqueM-3 Il y a 4 years, 6 months.

Assisté par: Minesh.

Auteur
Publications
#2289375

Tell us what you are trying to do?
Hello,
I have implemented the method described here (https://toolset.com/forums/topic/how-to-display-users-custom-fields-on-author-archive/) to display the author information at the top of the author archive page.
I'm having trouble generating the 'alt text' of the author's profile.
I would like that in this 'alt text' we find the full name of the author.
I tried the following:
alt="[wpv-user id="[get-author-id-in-archive][/get-author-id-in-archive]" field="user_firstname"] [wpv-user id="[get-author-id-in-archive][/get-author-id-in-archive]" field="user_lastname"]"
It doesn't work because of nested quotes.
I tried to alternate quotes and apostrophes but without success.

Is there a solution ?
Thank you

Is there any documentation that you are following?
https://toolset.com/forums/topic/how-to-display-users-custom-fields-on-author-archive/

What is the link to your site?
lien caché

#2289471

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

What if you try to use the following line of code, does that help you to fix your issue?

alt="[wpv-user id='[get-author-id-in-archive]' field='user_firstname'] [wpv-user id='[get-author-id-in-archive]' field='user_lastname']"
#2289821

Hello Minesh,

Thank you for your reply.

No unfortunatly it doesn't work.

[wpv-user id='[get-author-id-in-archive]' field='user_firstname']

does not return the first name for the author for the displayed author archive.

To display it I really need to write:

[wpv-user id="[get-author-id-in-archive][/get-author-id-in-archive]" field="user_firstname"]
#2291731

Minesh
Supporter

Is it possible for you to send me admin access details and problem URL where to what field you are trying to add the shortcode.

Let me see if I can offer you any other better workaround.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2291921

Minesh
Supporter

I've added the following shortcode to your theme's functions.php file to display the author image:

function func_display_alt_user_text($atts) {
  
    global $wp_query;
	
    $authorid = $wp_query->get_queried_object_id();
	
	$new_user = get_userdata( $authorid );
		
$first_name = $new_user->first_name;
$last_name = $new_user->last_name;
$name = $first_name.' '.$last_name;

	$x = get_avatar($authorid,96,'',$name,array('class'=>'avatar avatar-96 photo wpv-profile-picture-shape-circle'));
	
 
return $x;

 
}
add_shortcode("user_avatar_with_alt_text", "func_display_alt_user_text");

And calling the shortocde as given under outside the archive's loop:

 <figure class="bs-avatar">
[user_avatar_with_alt_text]  </figure>

Can you please confirm it works as expected.

#2291969

Hi Minesh,

Yes, it is exactly what I want to get.

Thank youvery much.

#2291971

My issue is resolved now. Thank you!