• Hello. Please tell me, how can i output subtemplate in the main theme, in the center content, where posts, etc usually outputed.

    I don’t want to use shortcodes for this. What are other options? Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    Use get_template_part() on the template currently used for the output where you want the subtemplate output to appear.

    Thread Starter BlackCatReal

    (@blackcatreal)

    get_template_part searches for subtemplate in main template folder of theme, and my subtemplate in my plugin folder… so it’s a bad option also.

    Moderator bcworkz

    (@bcworkz)

    Templates and plugins were never supposed to mix, but obviously the need arises. I found some code a while back that fools WP into thinking plugin templates are in a theme folder. It was meant for page templates, not template parts. Maybe it’ll still work for you. If it doesn’t, it’s probably just a matter of determining the proper buffer to hack to get it working.
    https://pastebin.com/t5KukZL9
    Make this code part of your plugin.

    its a long script tp type in in here, read this will help you and you may review it https://jeroensormani.com/how-to-add-template-files-in-your-plugin/

    Moderator bcworkz

    (@bcworkz)

    I’ve looked into this more. You’re right, get_template_part() searches the theme and child theme folders only. This is hardcoded into the function, there’s no buffer to manipulate.

    The only way to use plugin sub-templates is to override the main template with ‘template_include’ filter, and edit the plugin’s version of the main template to include the plugin sub-templates with include or require where ever get_template_part() is used.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to output my subtemplate in main theme using plugin?’ is closed to new replies.