I've a custom widget for ads, it helps me to show ads on sidebar but I'm trying to display it under every single post or on front page near to slider.
<?php the_widget( 'AdWidget_300' ); ?>
How could I call custom widget anywhere I want?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.Sign up to join this community
Add a widget area to your
home.php or whatever you want.. template's theme file. Than at the back-end go to Appearance > Widgets and move the widget to the widget area you just created.
We can't display custom widget directly in content or any other place.
the_widget() function only display built-in widget.
But still if you want display custom widget then you must create sidebar and assign widget to newly created sidebar and display that sidebar using
dynamic_sidebar( 'id' );.
For more information http://codex.wordpress.org/Widgetizing_Themes
Custom widget works well with
<?php the_widget( '' ); ?>
You can test it.
Copy widget example https://codex.wordpress.org/Widgets_API#Displaying_Widgets
Don't forget register as say in codex
add_action( 'widgets_init', ...
Call it from index.php
<?php the_widget( 'Foo_Widget' ); ?>
A clean, simple, and easy solution to your question is to look into the amr shortcode any widget. As the name suggests, you can insert your widgets in your pages by using shortcodes, like so:
[do_widget "Your Widget" ]