Where to put custom widget file?

If you created a custom widget, created a file by example class.my-widget.php containing the class definition of the custom widget, something like this: class my_widget extends WP_Widget { public function __construct() { //logic here } public function widget($args, $instance) { //logic here } public function form($instance) { //logic here } public function update($new_instance, $old_instance) { … Read more

Get rid of the widget Item Class=”widget-item”

The most straightforward way would be to overwrite this in your CSS file, for instance like this: .widgettitle { padding: 0; margin: 0; } Alternatively you can change the name of the class when registering your widget (possibly in your functions.php file) – look for the ‘before_title’ parameter. Here’s and example form the original twentysexteen … Read more

WordPress Shortcode function display outside of widget

I think the problem lies with functions like the_title() vs get_the_title() This seem to work: if (!function_exists(‘footer_get_latest_post’)) { function footer_get_latest_post() { $footerPost=””; $args = array(‘posts_per_page’ => 1 ); $recent_posts = new WP_Query($args); while( $recent_posts->have_posts() ) { $recent_posts->the_post(); $footerPost=”<div class=”footer-post-thumb”>” . get_the_post_thumbnail(‘thumbnail’) . ‘</div>’; $footerPost .= ‘<div class=”footer-post-content”><h3>’ . get_the_title() . ‘</h3>’; $footerPost .= get_the_content() . … Read more

Grabbing how Many Posts by Month for a Dashboard Widget

Just Went over your code and it looks fine but you are missing the code blocks for your foreach loops so: add_action(‘wp_dashboard_setup’, ‘dashboard_test’); function dashboard_test() { global $wp_meta_boxes; wp_add_dashboard_widget(‘month_dashboard’, ‘Reports Submitted for the Year’, ‘custom_test’); } function custom_test(){ global $wpdb; $years = $wpdb->get_col(“SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status=”publish” AND post_type=”report” ORDER BY post_date DESC”); … Read more

Archives shortcode displaying above widget title

Either use output buffering: // Email Archives Shortcode function email_archives_shortcode() { ob_start(); ?> <select name=”archive-dropdown” onchange=”document.location.href=this.options[this.selectedIndex].value;”> <option value=””><?php echo esc_attr( __( ‘Select Month’ ) ); ?></option> <?php wp_get_archives( array( ‘type’ => ‘monthly’, ‘format’ => ‘option’, ‘show_post_count’ => 1, ‘post_type’ => ’emails’ ) ); ?> </select> <?php return ob_get_clean(); } add_shortcode(’email-archives’, ’email_archives_shortcode’); Or a string function … Read more

Using a multiple element in widget form

I would remove the jQuery save function that was added… and then… Try this for the form function: public function form( $instance ) { // Code for editing/adding title and adding IDs to the <select> object // … <?php printf ( ‘<select multiple=”multiple” name=”%s[]” id=”%s” class=”widefat” size=”15″ style=”margin-bottom:10px”>’, $this->get_field_name(‘ID_list’), $this->get_field_id(‘ID_list’) ); // Each individual option … Read more

Hide certain widgets from specific user roles in admin

You have to check for Roles and Capabilities in the action hook widgets_init and proceed accordingly. add_action( ‘widgets_init’, ‘remove_widgets_wpse_89138’ , 15 ); function remove_widgets_wpse_89138() { // http://codex.wordpress.org/Function_Reference/is_admin if( !is_admin() ) return; // Grab current user info global $current_user; // Check for specific user /* $username = $current_user->user_login; if( ‘the_user_login’ != $username) return; */ // Check … Read more

How to position custom dashboard widgets on side column

You’re right – it doesn’t. Neither does the wp_add_dashboard_widget function. So just use the generic add_meta_box and indicate dashboard and placement: add_action( ‘wp_dashboard_setup’, ‘my_dashboard_setup_function’ ); function my_dashboard_setup_function() { add_meta_box( ‘my_dashboard_widget’, ‘My Widget Name’, ‘my_dashboard_widget_function’, ‘dashboard’, ‘side’, ‘high’ ); } function my_dashboard_widget_function() { // widget content goes here }

How do you Permanently Delete Sidebars

Thanks for the comment @Rarst! That was the issue. For whatever reason I had that extra sidebar method call in there and that was causing the problem. register_sidebar( array( ‘name’ => ‘Sidebar’ ) ); register_sidebar( array( ‘name’ => ‘Sub Menu’ ) ); WordPress saves the data from the widgets in the DB but it doesn’t … Read more