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?
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?
Add a widget area to your single.php
, front-page.php
, 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' ); ?>
@Bergmann,It is possible to display 5 ads in single page using single widget "if all ads are together" . But if you want all ads at different places , you have to create different widget areas and different widgets .
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" ]