Title: Applying PP programatically on HTML
Last modified: March 3, 2021

---

# Applying PP programatically on HTML

 *  Resolved [alx359](https://wordpress.org/support/users/alx359/)
 * (@alx359)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/applying-pp-programatically-on-html/)
 * Have been skimming through the code for a suitable hook to call PP onto a piece
   of HTML code that’s displayed via Ajax. Specifically, wish to apply PP’s URL 
   img rewrites to that HTML before the output reaches the browser. For example:
 * `<img src="https://www.domain.com/wp-content/plugins/phastpress/phast.php?service
   =images&src=https%3A%2F%2Fwww.domain.com%2Fwp-content%2Fuploads%2Fimage-247x296.
   jpg&cacheMarker=1597860358-49645&token=2386095927150b52" class="attachment-woocommerce_thumbnail
   size-woocommerce_thumbnail" alt="image" loading="lazy" title="image" width="247"
   height="296">`
 * Can you please tell an example of how to achieve that programmatically via a 
   hook? Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Albert Peschar](https://wordpress.org/support/users/kiboit/)
 * (@kiboit)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/applying-pp-programatically-on-html/#post-14132217)
 * Hi [@alx359](https://wordpress.org/support/users/alx359/),
 * I’ve added a helper function for this in the latest release 1.102. Update, and
   then try this:
 * `$optimized_html = phastpress_optimize_snippet("<img src='...'>");`
 * Let me know if this doesn’t do the trick.
 * –Albert
 *  Thread Starter [alx359](https://wordpress.org/support/users/alx359/)
 * (@alx359)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/applying-pp-programatically-on-html/#post-14133547)
 * It works, thank you so much! 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Applying PP programatically on HTML’ is closed to new replies.

 * ![](https://ps.w.org/phastpress/assets/icon-256x256.png?rev=1873505)
 * [PhastPress](https://wordpress.org/plugins/phastpress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/phastpress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/phastpress/)
 * [Active Topics](https://wordpress.org/support/plugin/phastpress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/phastpress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/phastpress/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [alx359](https://wordpress.org/support/users/alx359/)
 * Last activity: [5 years, 2 months ago](https://wordpress.org/support/topic/applying-pp-programatically-on-html/#post-14133547)
 * Status: resolved