• Hi, I have created a contact us form. I would like to auto populate one of the fields with the title of the post they came from.

    So i’m using contact form 7 and it is excepting the URL /form?instrument=XXXXX

    The XXX ideally wants to be the post title from the page they pressed the button on.

    So on the instrument posts I am using a plugin called Buttons Shortcode And Widgets to allow me to add a button on each post using sort codes. I current have the button code as

    [otw_shortcode_button href="[otw_shortcode_button href="/shop/form?Instrument=Instrument Name" size="medium" icon_position="left" shape="square" css_class="single_add_to_cart_button button alt"]Request Freebies[/otw_shortcode_button]

    is there away to change Instrument Name to be the posts title? I have many posts to add this button to, and do not want to edit it each time.

    Hope this makes sense…

Viewing 1 replies (of 1 total)
  • It is generally not a good idea to pass the post title in the url as some post titles may be very long and may have weird characters inside which may break the link.

    That aside, here’s a simple solution (simple as in it does not take care of the url encoding and weird characters). Note that this will only work if otw_shortcode_button shortcode supports nested shortcodes.

    First, create a shortcode for getting the post title.

    function title_shortcode( ){
       return get_the_title();
    }
    add_shortcode( 'title_shortcode', 'title_shortcode' );

    Then, replace “Instrument Name” with [title_shortcode]. The result code will look like this:
    [otw_shortcode_button href="[otw_shortcode_button href="/shop/form?Instrument=[title_shortcode]" size="medium" icon_position="left" shape="square" css_class="single_add_to_cart_button button alt"]Request Freebies[/otw_shortcode_button]

Viewing 1 replies (of 1 total)
  • The topic ‘Pass post title in URL’ is closed to new replies.