0

Is it possible to add a widget area to a custom wordpress theme? I've read many guides and I'm finishing to build a custom theme that will embed a simple layout builder based on shortcodes. I have my page and post page templates that are very simple in their structure:

<?php

get_header();

if( have_posts() ): while( have_posts() ): the_post();
the_title()
the_content();
endwhile;
endif; 
wp_reset_postdata();

get_footer();

?>

Can the widgets be added using the TinyMCE editor?
  • You should be able to make a custom shortcode with one argument - the name of the sidebar - and have the shortcode output the full sidebar with widgets. But authors would manage the actual sidebar contents in the Appearance > Widgets area, which is not a very page-builder-like experience. – WebElaine Oct 15 at 18:52
  • @WebElaine for a custom shortcode I need to know what widget will be added, but I want that the user only add the [shortcode] and get the widget in place,so I need to call it using some wp functions in my class? I'm not planning to create a page builder experience at all. – userone2 Oct 16 at 8:45
  • Hmm, normal behavior is that you add a whole sidebar and it can contain any necessary widgets. I'm not sure how you would be able to determine what widget they're wanting to include. If it's something that can wait for future development, the Core team is working toward eventually making everything a block - so widgets would be included. Depending on which widgets you want them to be able to add, there are some already available as blocks, if you want to try the Block Editor and see if it has enough of what you need. – WebElaine Oct 16 at 13:36
  • @WebElaine I'm not using gutemberg but the classic editor that I think is the best. I will create a shortcode and then using the shortcode attributes I will try to register a sidebar. I need to call the register_sidebar() function right? the get_sidebar() function can be called from the editor or I need to add it to the page/post template? – userone2 Oct 17 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.