Bonjour,

Sur mon site wordpress, je souhaiterai ajouter un bouton partage en shortcode.
Sur ma page function.php j'ai :

function fond_mon_shortcode( ) {

   $code_html = "<a target='_blank' style='margin-right:15px;' href='mailto:?subject=Fonds De Dotation  vol de nuits - <?php the_title(); ?>&body=Voici un projet du Fonds De Dotation vol de nuits <?php the_permalink(); ?>' rel='nofollow' data-title='Envoyer par mail' title='Envoyer par mail'>Partager</a>";
  return $code_html;
}
add_shortcode( 'fondshortcode', 'fond_mon_shortcode' );

Sur ma page d'article j'ai mon shortcode :
[fondshortcode]

Mais cela ne marche pas. Le mail ne s’écrit, ni avec le lien , ni avec le titre de la page... Le bouton fonctionne, mais les elements en php dans mailto ne marche pas eux... <?php the_title(); ?> et <?php the_permalink(); ?> restent tel quel.

Il y a un truc que je fais mal, mais je n'arrive pas à savoir quoi.. Savez-vous ?

5 réponses


silencesim
Auteur
Réponse acceptée

ça marche comme ça !!!
Merci

// shortcode
function fond_mon_shortcode( ) {
    $the_title = get_the_title();
    $the_permalink = get_permalink();

    return $code_html = "<a style='margin-right:15px;' href='mailto:?subject=Fonds De Dotation  vol de nuits - $the_title&body=Voici un projet du Fonds De Dotation vol de nuits $the_permalink' rel='nofollow' data-title='Envoyer par mail' title='Envoyer par mail'>Partager</a>";
}
add_shortcode( 'fondshortcode', 'fond_mon_shortcode' );

As-tu essayé quelque chose de ce genre :

function fond_mon_shortcode( ) {
    $the_title = the_title();
    $the_permalink = the_permalink();

    return $code_html = "<a target='_blank' style='margin-right:15px;' href='mailto:?subject=Fonds De Dotation  vol de nuits - $the_title&body=Voici un projet du Fonds De Dotation vol de nuits $the_permalink rel='nofollow' data-title='Envoyer par mail' title='Envoyer par mail'>Partager</a>";
}
add_shortcode( 'fondshortcode', 'fond_mon_shortcode' );

?

Salut Oez,
Merci
Par contre ça ne marche pas le titre et le lien de la page s'affiche sur la page et pas dans le mail.

et ceci :

function fond_mon_shortcode( ) {
  return $code_html = "<a target='_blank' style='margin-right:15px;' href='mailto:?subject=Fonds De Dotation  vol de nuits -" . the_title() . "&body=Voici un projet du Fonds De Dotation vol de nuits" . the_permalink() . " ' rel='nofollow' data-title='Envoyer par mail' title='Envoyer par mail'>Partager</a>";
}
add_shortcode( 'fondshortcode', 'fond_mon_shortcode' );

tu peux aussi essayer avec les Curly Braces

?

ça fait pas de difference.... grr comprend pas