Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere do I put my custom widget code for my wordpress theme?
    text
    copied!<p>I am creating a custom widget for my wordpress theme. The code I have breaks at a certain point.</p> <p>I do not want to package the widget as a plugin so I am putting my code in the functions.php file.</p> <p>This is my code:</p> <pre><code>class gmp_widget extends WP_Widget { function gmp_widget() { // widget actual processes $widget_ops = array('classname' =&gt; 'gmp_widget', 'description' =&gt; __('Example widget that displays a user\'s bio.','gmp-plugin')); $this-&gt;WP_Widget('gmp_widget_bio', __('Bio Widget','gmp-plugin'), $widget_ops); } public function form( $instance ) { // outputs the options form on admin $defaults = array( 'title' =&gt; __('My Bio', 'gmp-plugin'), 'name' =&gt; '', 'bio' =&gt; ''); $instance = wp_parse_args( (array) $instance, $defaults); $title = strip_tags($instance['title']); $name = strip_tags($instance['name']); $bio = strip_tags($instance['bio']); &lt;p&gt;&lt;?php _e('Title', 'gmp-plugin') ?&gt;: &lt;input class="widefat" name="&lt;?php echo $this-&gt;get_field_name('title'); ?&gt;" type="text" value="&lt;?php echo esc_attr($name); ?&gt;"&lt;/p&gt; &lt;p&gt;&lt;?php _e('Name', 'gmp-plugin') ?&gt;: &lt;input class="widefat" name="&lt;?php echo $this-&gt;get_field_name('name'); ?&gt;" type="text" value="&lt;?php echo esc_attr($name); ?&gt;"&lt;/p&gt; &lt;p&gt;&lt;?php _e('Bio', 'gmp-plugin') ?&gt;: &lt;textarea class="widefat" name="&lt;?php echo $this-&gt;get_field_name('bio'); ?&gt;" &lt;?php echo esc_attr($title); ?&gt;&lt;/textarea&gt;&lt;/p&gt; } public function update( $new_instance, $old_instance ) { // processes widget options to be saved $instance = array(); $instance['title'] = strip_tags($new_instance['title']); $instance['name'] = strip_tags($new_instance['name']); $instance['bio'] = strip_tags($new_instance['bio']); return $instance; } public function widget( $args, $instance ) { // outputs the content of the widget extract($args); echo $before_widget; $title = apply_filters('widget_title', $instance['title'] ); $name = empty($instance['name']) ? '&amp;nbsp;' : apply_filters('widget_name', $instance['name']); $bio = empty($instance['bio']) ? '&amp;nbsp;' : apply_filters('widget_bio', $instance['bio']); if ( !empty( $title ) ) { echo $before_title . $title . $after_title; }; echo '&lt;p&gt;' .__('Name', 'gmp-plugin') .': ' . $name . '&lt;/p&gt;'; echo '&lt;p&gt;' .__('Bio', 'gmp-plugin') .': ' . $bio . '&lt;/p&gt;'; echo $after_widget; } } </code></pre> <p>When it gets to the function form ($instance) I can see that the p tags are giving a syntax error as all the code below this goes from looking correct and all the right colour to black in my text editor which tells me there is a problem somewhere but I cannot figure out what it is. Any help will be greatly appreciated! Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload