Support » Plugin: Visual Link Preview » 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 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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Brecht


    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


    ok. Anyway I integrated your shortcode with opengraph.php and managed to do it programmatically.

    Plugin Author Brecht


    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.