WordPress.org

Ready to get started?Download WordPress

Forums

How to embed a widget into a post or page? (6 posts)

  1. jpxwordpress
    Member
    Posted 6 years ago #

    Hi, I would just like to know how to include a widget (or contents desired from a widget) directly into a post or page. I have been searching for this a lot in the WP forums to no avail. I'm sure it is possible to embed the contents of a widget or latest posts from a given category for example directly into a post or page by including the proper call to the right WP function, but that might be a tricky for those who are not at a certain programmer level I think.

    Thanks to everyone who can help! : - ]

  2. Austin Matzko
    Member
    Posted 6 years ago #

    This is pretty straightforward. Edit the theme template file, and wherever you want the widget section to be, put the following lines:

    <?php if (!dynamic_sidebar('some name for this widgets section') ) : ?>
    <?php endif; ?>

    Then, in your theme's functions.php file, put the following:

    register_sidebar(array('name' => 'some name for this widgets section'));

  3. jpxwordpress
    Member
    Posted 6 years ago #

    Filosofo, thanks a lot for your reply! I am wondering though, on first look, this code appears to apply to an ENTIRE THEME rather than just one individual page or post on an "on-the-fly" basis - will this still work only for one post? And I, like other users too I think from searching through the forums, have trouble locating the WIDGET NAME in the sidebar or dynamic sidebar.

    Thanks a lot for your help.

  4. moshu
    Member
    Posted 6 years ago #

    will this still work only for one post?

    Nope.

  5. Austin Matzko
    Member
    Posted 6 years ago #

    You can make the code apply to only one page by using page templates.

    To make it apply to only one post, you could add something like the following to your theme's functions.php file, where custom_template.php is the name of the file that has the custom sidebar, and "123" is the ID of the post you wish to apply it to:

    function custom_single_post() {
            if ( is_single(123) ) {
                    include(TEMPLATEPATH . '/custom_template.php');
                    exit;
            }
    }
    add_action('template_redirect','custom_single_post');
  6. Anonymous
    Unregistered
    Posted 6 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic