How do I use add_action on custom widget?

when calling a function within a class you need to use $this prefixadd_action(‘wp_head’,array(&$this,’load_face’)); and you will need to populate the value of $sex public function load_face($instance) { $sex = $instance[‘sex’]; wp_enqueue_style(‘style’, WP_PLUGIN_URL . ‘/sample/’.$sex.’.css’, null, null, ‘screen’); }

Best practice for including plugin output in a template without using shortcode?

<?php // A) // inside your template if ( function_exists( ‘the_attachment_stuff()’ ) ) { // do stuff } // better/faster if ( class_exists( ‘attachment_plugin_class’ ) ) { // do stuff } // B) // inside your template do_action( ‘the_attachment_suff’); // means setting this inside your plugin // this avoids throwing errors or aborting if the … Read more

Modify WordPress widgets Screen

I’d personally suggest an enqueue, it’s preferable where possible to make use of caching and script compression. Firstly, the enqueue. add_action( ‘admin_enqueue_scripts’, ‘add_sidebar_ids_to_widget_admin’ ); function add_sidebar_ids_to_widget_admin( $current_page_hook ) { if( ‘widgets.php’ != $current_page_hook ) return; wp_enqueue_script( ‘widget-admin-jquery’, get_stylesheet_directory_uri() . ‘/widget-admin-jquery.js’, array( ‘jquery’ ), ‘1.0’, true ); } I placed the code in a child theme’s … Read more

Remove the Inactive Widgets

function andrew_unregister_widgets() { unregister_widget( ‘WP_Widget_Archives’ ); unregister_widget( ‘WP_Widget_Calendar’ ); unregister_widget( ‘WP_Widget_Categories’ ); unregister_widget( ‘WP_Widget_Links’ ); unregister_widget( ‘WP_Widget_Meta’ ); unregister_widget( ‘WP_Widget_Pages’ ); unregister_widget( ‘WP_Widget_Recent_Comments’ ); unregister_widget( ‘WP_Widget_Recent_Posts’ ); unregister_widget( ‘WP_Widget_RSS’ ); unregister_widget( ‘WP_Widget_Search’ ); unregister_widget( ‘WP_Widget_Tag_Cloud’ ); unregister_widget( ‘WP_Widget_Text’ ); } add_action( ‘widgets_init’, ‘andrew_unregister_widgets()’ ); This unregisters all in-built wordpress widgets. Which ones of those are … Read more

Dynamic Sidebar and XHTML Validity?

I’ve had similar issues in the past with custom sidebars. It was caused by the improper use of the <ul> and <li> tags. I was adding them in the sidebar.php file and not inside the function. Now I use this code and with 6 active widgets I have no errors. Take a look at the … Read more