Title: Insert VLP programmatically by shortcode on form submission
Last modified: June 30, 2020

---

# Insert VLP programmatically by shortcode on form submission

 *  [gauravkeerthi](https://wordpress.org/support/users/gauravkeerthi/)
 * (@gauravkeerthi)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/insert-vlp-programmatically-by-shortcode-on-form-submission/)
 * I would like to pass a link from a form submission and programmatically update
   the post content with a shortcode
    `$content1 = '[visual-link-preview type="external"
   url="'.esc_url($_POST['article1']) .'"]';` but this results in an error. For 
   the block, all i need to do is call the URL and it retrieves and generates the
   visual link preview. For the shortcode, it does not (as you mentioned). Hence,
   I suggested that I think this is a useful feature.In the interim, how would you
   suggest I achieve what I was looking to do? is there a way for me to insert it
   via code such that it pulls the headline/excerpt/image and saves it to the post
   without manual intervention?
 *     ```
        $content1 = '[visual-link-preview type="external" url="'.esc_url($_POST['article1']) .'"]';     // article1 is a URL submitted by users
       // other code
        if(wp_insert_post( array(
              'post_title' => esc_url_raw($_POST['article1']),
              'post_content' => $content1, // this is what i want to achieve
              'post_type' => 'article',
              'post_status' => 'draft'
              ) )) 
       // other code
       ```
   
 * When I try the above code (calling the shortcode just with an external url) my
   front end throws up a few notices in debug mode, which implies that i did not
   pass in these variables (but not sure why i need to since this is not a [documented requirement](https://help.bootstrapped.ventures/article/262-manually-construct-the-vlp-shortcode)
   for the shortcode):
 * Notice: Undefined property: stdClass::$title in ms_wp/wp-content/plugins/visual-
   link-preview/includes/public/class-vlp-link.php on line 53
 * Notice: Undefined property: stdClass::$summary in ms_wp/wp-content/plugins/visual-
   link-preview/includes/public/class-vlp-link.php on line 54
 * Notice: Undefined property: stdClass::$template in ms_wp/wp-content/plugins/visual-
   link-preview/includes/public/class-vlp-link.php on line 55
    -  This topic was modified 5 years, 11 months ago by [gauravkeerthi](https://wordpress.org/support/users/gauravkeerthi/).

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

 *  Plugin Author [Brecht](https://wordpress.org/support/users/brechtvds/)
 * (@brechtvds)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/insert-vlp-programmatically-by-shortcode-on-form-submission/#post-13052241)
 * I just noticed the documentation is a little bit unclear. The shortcode does 
   need to look like that first example, with all of those fields set.
 * The rest of the documentation (with the shorter shorcodes) was only meant to 
   explain those different options. I’ll try to clarify that.
 * There is no way to automatically retrieve that information at the moment as that’s
   done through JavaScript and the shortcode uses PHP.
 *  Thread Starter [gauravkeerthi](https://wordpress.org/support/users/gauravkeerthi/)
 * (@gauravkeerthi)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/insert-vlp-programmatically-by-shortcode-on-form-submission/#post-13052808)
 * ok. Anyway I integrated your shortcode with opengraph.php and managed to do it
   programmatically.
 *  Plugin Author [Brecht](https://wordpress.org/support/users/brechtvds/)
 * (@brechtvds)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/insert-vlp-programmatically-by-shortcode-on-form-submission/#post-13052813)
 * Happy to hear that works for you! I’ll look into integrating something like that
   for the next update as well, in case others want this functionality.

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

The topic ‘Insert VLP programmatically by shortcode on form submission’ is closed
to new replies.

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

 * 3 replies
 * 2 participants
 * Last reply from: [Brecht](https://wordpress.org/support/users/brechtvds/)
 * Last activity: [5 years, 11 months ago](https://wordpress.org/support/topic/insert-vlp-programmatically-by-shortcode-on-form-submission/#post-13052813)
 * Status: not resolved