Pages with 2 Columns

Here is an interesting approach: THE PLAN AND LOGIC: Custom fields are a build in functionality that will fit our needs perfectly. We can set a new custom field and then use that field to enter and store our custom data. We can then use a widget to display this custom content in the sidebar … Read more

Adding inline styles from a widget

Got it. So here’s how you insert a hover state halfway the processing of a page without violating the w3c rules. This is the code you don’t want your widget to produce: <div class=”mywidget”> <style>.mywidget a {color:red}, . mywidget a:hover {color:blue;}</style> <a>Link</a> </div> The following validates and is fairly elegant. In your widget generate the … Read more

Add a banner to the Dashboard

Workaround using jQuery DOM insertion. Note the use of PHP Heredoc sintax to print the script. function wpse_53035_script_enqueuer(){ echo <<<HTML <script type=”text/javascript”> jQuery(document).ready( function($) { $(‘<div style=”width:100%;text-align:center;”><img src=”http://cdn.sstatic.net/wordpress/img/logo.png?v=123″></div>’).insertBefore(‘#welcome-panel’); }); </script> HTML; } add_action(‘admin_head-index.php’, ‘wpse_53035_script_enqueuer’); This inserts the new div at the top before #welcome-panel. If you use the div #dashboard-widgets-wrap it prints in the same … Read more

Hooking Into Widget Output Loop

Hook into ‘dynamic_sidebar’ and count how often it is called. You get the current active sidebar with key( $GLOBALS[‘wp_registered_sidebars’] ). add_action( ‘dynamic_sidebar’, ‘wpse_96681_hr’ ); function wpse_96681_hr( $widget ) { static $counter = 0; // right sidebar in Twenty Ten. Adjust to your needs. if ( ‘primary-widget-area’ !== key( $GLOBALS[‘wp_registered_sidebars’] ) ) return; if ( 0 … Read more

Transform php code into a widget?

Here is a stand-alone answer. Building a widget to echo hard-coded PHP is trivial. class PHP_Widget_wpse_80256 extends WP_Widget { function __construct() { $opts = array( ‘description’ => ‘Display Some Hard Coded PHP content’ ); parent::WP_Widget( ‘my-hc-php-content’, ‘Some PHP’, $opts ); } function widget($args,$instance) { // PHP goes here, like this: echo ‘PHP generated content’; } … Read more