Wordpress: Function to add images in text editor -


I'm really new to Wordpress and gradually getting my head around it, but I have come into a problem and I do not know how to fix it.

I am creating a page using text editor in backend and I paste the html there. All are working fine and I can output images to functions.php using this function (I've got this snippet anywhere but I do not remember)

  // Create shortcode template_url ($ atts, $ content = null) {return '& lt; Img src = "'. Get_template_directory_uri ().' / '. $ Content.'" Alt = "" /> gt; '; } // Add as shortcode code add_shortcode ("template", "template_url");   

And I call it like this

  [template] picture / my-image.jpg [/ template]   

The problem is how do I add some alt text and add a class for the image

< p> You can add shortcode with your custom attributes like this: -

Add the following code to add the shortcode: < Pre> function template_url ($ atts, $ content = null) {extract (shortcode_ts (array ('alt' => gt; '', 'width' = & gt; '', 'heig Ht '= & gt;' '), $ atts)); // And you can use this variable in this way: - Return '& lt; img src = "'. get_template_directory_uri ().' / '. $ contents.'" alt = "'. alt alt."' width = "'. $ Width '"Height ="' $ Height Use this shortcode in the add_shortcode ("template", "template_url");

and in the editor: -

  [ Template alt = "this change is text" width = "400" height = "300"] image / my image .jpg [/ template]   

I hope this will be useful.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -