• Can I add widget in pages and posts using short codes without any plugin or additional codes?

    I mean I need search and text widgets in posts and pages.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,
    yes, you can.
    For the search widget,

    function post_searchform( $form ) {
        $form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
        <div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
        <input type="text" value="' . get_search_query() . '" name="s" id="s" />
        <input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
        </div>
        </form>';
    
        return $form;
    }
    
    add_shortcode('mysearch', 'post_searchform');

    For the text widget, add your text widget content inside the shortcode function.

    Thread Starter Justine007

    (@justine007)

    I placed the code in functions.php of child theme, then I add a text widget in footer widget area and put [mysearch]. But didnt work for me. But it is working in pages when I adding this short code.

    https://ordinary1.esy.es/wordpress1/

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can I add widget in pages and posts without any plugin or additional codes’ is closed to new replies.