View post button

This topic contains 3 reply and 2 voices, and was last updated by Rob 9 years, 9 months ago
Viewing 3 Posts - 1 through 3 (of 3 total)
Author Posts
February 9, 2015 at 2:17 am 36140
Rob Hi Is there an easy way to add a "view post" button/link into a post edit form?
February 9, 2015 at 7:24 am 36149
Rob Rob

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' );
February 12, 2015 at 5:58 pm 36588
towhid towhid

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.

February 13, 2015 at 2:34 am 36628
Rob Rob

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 3 Posts - 1 through 3 (of 3 total)