<? php echo get_template_directory_uri ();?> / images / image.jpg ne fonctionne pas dans la barre latérale
3 réponses
- votes
-
- 2012-08-08
Le code PHPne fonctionnerapas à l'intérieur d'un widgettexte.Ilexiste desplugins qui vouspermettront defaire cela,mais cetype de choseestfortement déconseillé.
Ajoutez ce code à votrefichierfunctions.php,oumieuxencore,faites-en un simplepetit plugin:
// Enable the use of shortcodes within widgets. add_filter( 'widget_text', 'do_shortcode' ); // Assign the tag for our shortcode and identify the function that will run. add_shortcode( 'template_directory_uri', 'wpse61170_template_directory_uri' ); // Define function function wpse61170_template_directory_uri() { return get_template_directory_uri(); }
Pour l'utiliser dans l'administrateur,ajoutez le shortcode
[template_directory_uri]
à votre widgettexte,et le répertoire dumodèle sera affichéparexemple[template_directory_uri]/images/image.jpg
PHP code won't run inside of a text widget. There are plugins that will let you do that, but this type of thing is strongly discouraged.
Add this code to your functions.php file, or better yet, make it a simple little plugin:
// Enable the use of shortcodes within widgets. add_filter( 'widget_text', 'do_shortcode' ); // Assign the tag for our shortcode and identify the function that will run. add_shortcode( 'template_directory_uri', 'wpse61170_template_directory_uri' ); // Define function function wpse61170_template_directory_uri() { return get_template_directory_uri(); }
To use it in the admin, add the shortcode
[template_directory_uri]
to your text widget, and the template directory will be output e.g.[template_directory_uri]/images/image.jpg
-
Aucunproblème,et bienvenue sur WPSE!Pouvez-vous cliquer sur la cochepour accepter cette réponse?Merciet bravo!No prob, and welcome to WPSE! Could you please click the check mark to accept this answer? Thanks, and cheers!
- 1
- 2012-08-08
- Dave Romsey
-
- 2012-08-08
Vouspouvez utiliser un widgetphp,quiest un widget detextebrut adaptépourpouvoirexécuterphp.Voir WordPress ›Widget de code PHP« Plugins WordPress par http://ottodestruct.com
You can use a php widget, which is a plain text widget adapted to be able to execute php. See WordPress › PHP Code Widget « WordPress Plugins by http://ottodestruct.com
-
- 2012-08-08
Une solution simple serait detélécharger l'image sur le supportet d'utiliser l '
url
comme src de l'image dans le widgettexte.A simple solution would be to upload the image to media, and use the
url
as the src for the image in the text widget.
Enespérant que quelqu'unpuisse répondre à cette question!
J'utilise cecipourmonen-têteet celafonctionne:
Mais lorsquej'essaie de l'utiliser dans un widget detexte de labarre latérale,l'imagene s'affichepas.Desidées?