Print post from admin with custom template
-
Hi, I’ll try to keep it short and clear.
I need to add a button in the edit post screen which allows the user to see all the post data in a print-friendly template.
It’s a custom post type with lots of custom fields.The button is not a problem, I think I’ll add it to the admin bar.
The problem is with the custom template.I’ll explain my possible solution but I think there are better methods.
I create a plugin with a custom PHP file with the “print-friendly” template and I call this file when I click on the button. I’ll pass the post ID in a URL parameter.
So, the button link will be something like this: https://mywebsite.com/path/to/plugin/print-friendly.php?id=1234
When the user clicks on the button, a new tab opens with my print-friendly template and the post data. Then the user can print it using the browser print functionality.
The issue is that in my custom PHP file I can’t use the WordPress functions. I’ll need to include the “wp-load” file in order to do this.
I know that using a custom PHP file and the including “wp-load” is not a good thing to do.
Any advices?
- The topic ‘Print post from admin with custom template’ is closed to new replies.