Answer the question
In order to leave comments, you need to log in
What is the best way to add plugin markup to the content area of a Wordpress page?
I am creating a plugin - a calculator, a form, a graphics editor (whatever).
It is added to the page using a shortcode. I configure everything in a shortcode. What is the optimal way to add plugin markup to a page?
I don't need to redefine the entire template. footer, header and everything else, let it be in place. I only need to change the content. Is there a way to override the content template? I did it "on the forehead" - like this:
function load_table_manager()
{
wp_enqueue_style('table_manager_css',"//handsontable.com/dist/handsontable.full.css");
ob_start();
include dirname(__FILE__) . '/template.php'; // здесь вся нужная разметка
$result = ob_get_contents();
ob_end_clean();
table_manager_scripts(); // функция для подгрузки JS через wp_enqueue_script
return $result;
}
add_shortcode('table_manager','load_table_manager');
Answer the question
In order to leave comments, you need to log in
It seems to me "crooked" is the very fact that you completely change the page template with a widget, why? When can you just make a page template?
A widget is usually just some separate block with information, and not the entire content. If you make a full page calendar, it's not a widget, it's a calendar. Substitution of concepts.
Terminology:
A widget is a small information block placed on the Yandex home page. It usually contains data or a service from another site, such as news, latest forum posts, a random joke, job search, and so on.
Taken from https://yandex.ru/support/widgets/
Create a file such as Custom-page.php
and specify
<?php
/*
* in the beginning
* Template Name: Template name
*
*/
?>
After that, when adding a page, you can specify it at the bottom right in the Page Attributes section - Template
And of course, do not forget that you need to add a header and footer to this file
Alexander, thanks for the answer, but let's get to the bottom of the issue:
It seems to me "crooked" is the very fact that you completely change the page template with a widgetI write that I do not change the page template. My code just doesn't touch the template, it inserts MY markup into the content area. Look, here it is written:
.... I don't need to redefine the entire template. footer, header and everything else, let it be in place. I only need to change the content.I specifically wrote about this...
function get_custom_post_type_template($single_template) {
global $post;
if ($post->post_type == 'data_table') {
$single_template = dirname( __FILE__ ) . '/template.php';
}
return $single_template;
}
add_filter( 'single_template', 'get_custom_post_type_template' );
pull up the hat and footer. That is, to perform some other actions, but in my example it is not necessary to do this. The markup I need is inserted into the finished site template. The rest of the page remains standard. Here also it is interesting to me, than the approach resulted by me is bad. I would like real arguments.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question