Use dynamic urls from post page to form page in gutenberg editor

37 Views Asked by At

I'm trying to use query parameters to prefill a jetpack contact form on a separate page. It's a woocommerce single product template page with a link like this:

<a href="/inquiry-page?g1811-original=[post_title]">Inquire</a>

I want to dynamically populate the post title (or post id, whatever works) in the url so when I get to the inquiry page it pre-fills the title in the field in the inquiry form:

<input type="text" name="g1811-original" value="" placeholder="" required="" aria-required="true">

Right now the pre-fill works but the field just says "[post-title]". I'm trying to do this with shortcodes or similar in the Gutenberg editor without resorting to javascript/PHP if possible. Is there a way to use the visual editor or code editor to do this?

EDIT: I've tried using woocommerce shortcodes but they didn't work either

1

There are 1 best solutions below

0
Yawner On

I realized [post_title] didn't exist, so I created a custom shortcode. For some reason, other woocommerce shortcodes weren't working on the page, so I used these instructions. I added this through WPCode plugin but here's another more complete answer.

/**
  * @snippet       Echo Current Product/Post Name (Shortcode)
  * @usage         Use [post_title] on the current post
  * @compatible    WooCommerce 8
  */

  add_shortcode( 'post_title','get_the_title' );

After that inserting /art-inquiry?g1811-original=[post_title] in the Gutenberg link editor printed the title of the product into the url /art-inquiry?g1811-original=The%20Post%20Title which pre-filled the jetpack form.