0

I have a custom page template and I want it to display as a sidebar.

How to do this? I google it but I did not find any articles/topics about this.

Or how can I create a shortcode for this custom page template?

1 Answer 1

1

Use a shortcode include plugin and simply add a shortcode inside a text widget in the sidebar you'll be using on the widgets or customizer page.

Here are some example plugins and how they work:

Include Me - [includeme file=”filename.php”]

Custom Content Shortcode - [load file=template/sidebar.html]

Insert Pages Plugin - [insert page='{slug}|{id}' display='title|link|content|all|{custom-template.php}']

Include Shortcode - [include slug="hello-world"]


You could also simply duplicate the template and rename it to sidebar-{pagename}

Duplicate page template, remove commented header inside the file, and rename it sidebar-custom.php.

Then just include that inside the other page template where you want to use it.

<?php get_sidebar ('custom'); ?>

Other methods if you don't want to rename add another file just include it in your template like a sidebar:

(will return template-name.php)

include ('template-name.php'); 

(will return template-name.php)

include(get_query_template('template-name'));

(will return template-name.php)

locate_template(template-name.php, true);

(will return content-page.php)

get_template_part( 'content', 'page' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.