DEV Community


Posted on

Adding a new widget to a WordPress theme - to add more ads

Adding a new widget to a WordPress theme like Jobify by Astoundify requires some coding skills and knowledge of the theme's structure. Here are the steps we can follow to add a new widget to Jobify that allows users to submit ads:

first we create a child theme: It's always recommended to create a child theme of Jobify instead of modifying the parent theme directly. This way, our changes won't be lost when the parent theme is updated.

Create a new widget: In our child theme's directory, we create a new PHP file for our widget. We can use the WordPress Widget API to create the widget.
Here's an example code snippet that we can use as a starting point:

`class Jobify_User_Ad_Widget extends WP_Widget {

function construct() {
_('User Ad Widget', 'jobify'),
array('description' => _
('Allows users to submit ads', 'jobify'))

public function widget($args, $instance) {
// Widget output

public function form($instance) {
// Widget form

public function update($new_instance, $old_instance) {
// Update widget settings


  1. Add the widget to Jobify's widget areas: Now that we have created the widget, we need to add it to the widget areas in Jobify. We can do this by editing our child theme's functions.php file and adding the following code:

function jobify_register_user_ad_widget() {
add_action('widgets_init', 'jobify_register_user_ad_widget');

  1. here we add the ad submission functionality: To allow users to submit ads, we can use a plugin like WPForms or Gravity Forms to create a form. We can then add this form to our widget's widget() method. Here's an example code snippet:

`public function widget($args, $instance) {
// Display the widget title
echo $args['before_widget'];
if (!empty($instance['title'])) {
echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];

// Display the ad submission form
echo do_shortcode('[gravityform id="1" title="false" description="false"]');

echo $args['after_widget'];

In this example, the Gravity Forms shortcode [gravityform id="1" title="false" description="false"] is used to display the ad submission form.

we can replace this with the shortcode for your own form.

Style the widget: Finally, we can style the widget to match Jobify's design by adding CSS to your child theme's style.css file.

With these steps, we should be able to add a new widget to Jobify that allows users to submit ads.

Top comments (0)