Hello! Wordpress has a portfolio on it that displays entries and, when pressed, displays a picture in a lightbox. How to display the characteristics of the product in the lightbox? I can’t add php code to the js lightbox file. Is it possible?

  • Javascript can get data that is stored in the database, only with the help of php. Accordingly, if you have prepared the necessary information for js, then you can use it in javascript code. - Ponio
  • There is no php code in the js file that you cannot add, but you can display the information you need in the page template, and then manipulate this data from JS. Or send a request to the server from js and process the received response as necessary. - pepel_xD

1 answer 1

Usually, the data obtained through PHP in the WordPress template is “localized” using the wp_localize_script function, and only then from javascript they work with them and pass to lightboxes.

  • What is a minus? Can you argue? - mihdan
  • Judging by the fact that the author wants to write php code in js files, you can not bathe at the expense of the minuses. - pepel_xD
  • And so, yes. I will explain a little: This function adds additional data before the specified script, which should be in the output queue. In fact, using it, before outputting the script, an object with dynamic data is output via php, and then used in the main JS script. - pepel_xD