Home Forums Plugin Support WP User Frontend Pro View post button

This topic is: not resolved

This topic contains 3 replies, has 2 voices, and was last updated by  Rob 4 years, 4 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #36140

    Rob
    Member
    Post count: 101

    Hi

    Is there an easy way to add a “view post” button/link into a post edit form?

    #36149

    Rob
    Member
    Post count: 101

    Actually I seem to have sorted it.

    Add an action hook in the form (in this case called “view_post_button”) and put the following into functions.php. The button will only appear in an edit post screen, not in a new post (makes sense).

    /*-- View Listing button in add/edit listing ---*/
    function render_post_button(){
    	$listingid=$_GET['pid']; 
    	if ($listingid != '' ) {
    		$url = site_url() . '/?p=' . $listingid;
    		echo '<div style="float:right;"><a title="View this listing in a new tab" class="button" href="' . $url . '" target="_blank">View Listing</a></div>';
    	}
    }
    add_action( 'view_post_button','render_post_button' );
    #36588

    towhid
    Participant
    Post count: 4505

    Hello Rob,

    Did you tried your own, then what was the result?

    I tried in my theme's functions.php but no button appear in post edit form.

    #36628

    Rob
    Member
    Post count: 101

    The trick is in the words “Add an action hook in the form (in this case called “view_post_button”)”.

    In your form, add a field called “action hook” and put “view_post_button” in both fields. Update etc. Then you can style the button using the class “button”

    I can't show you mine because it's on a protected page.

    That's it. Hope this helps

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘View post button’ is closed to new replies.