sebastian sledz sebastian sledz - 15 days ago 8
PHP Question

How to display result of PHP render in HTML ID

this is my first question here. After digging internet for an answer I cannot find any idea about how to deal with my issue. I think the problem is common for someone who knows PHP a little bit.

To describe the situation. For some custom WordPress plugin I've got two PHP files: ff_config.php and loantest_form.php. First file contains some configurations of plugin plus following lines:

/**--------------------------TABLE SHORTCODES-----------------------*/
function render_loantest_form() {
include(plugin_dir_path(__FILE__) . 'front/loantest_form.php');
}
add_shortcode( 'render_loantest_form' , render_loantest_form );

/**--------------------------DISPLAY PLUGIN IN FOOTER-----------------------*/
add_action('wp_footer', 'display_loantest');
function display_loantest() {
echo render_loantest_form();
}


which I suppose rendering second file containing enqueue scripts (js/css) and whole HTML output and placing in wp_footer where it exactly is on my page.

The question is: how to change mentioned lines to allow me to place render result (loantest_form.php) in specific div / id on page (for example #sidebar-slider)?

Many thanks for help, cheers!

Answer

If you want to display your shortcode in a template file,

echo do_shortcode('[render_loantest_form]');

Enable the use of shortcodes in text widgets.

add_filter( 'widget_text', 'do_shortcode' );

And inside the text editor

[render_loantest_form]

You can read more about do_shortcode()

Note that you need to be sure that the file load in the render function is good and that it returns the expect content.