Change template dynamically

Just in case someone comes here to copy pasta without looking at the codex. THE APPROPRIATE FILTER IS »template_include« See: Codex – Filter Reference As Radek pointed out that method can destroy your theme. Additional information: The article »Don’t use template_redirect to load an alternative template file« by Mark Jaquith, where he says, in a … Read more

How do I include background images in my stylesheets in a plugin?

Just add a STYLE tag in ‘wp_head’. // Anonymous function, PHP 5.3+, extract function for 5.2 add_action(‘wp_head’, function(){ echo ‘<style type=”text/css”>’; // Add background style here echo ‘</style>’; }); Add this in your functions.php. Don’t stuff too much CSS in it, just the dynamic bg image you need. It’s not the easiest thing to create … Read more

“You do not have sufficient permissions to access this page” upon accessing my newly created plugin page

add_options_page(“OSCommerce Product Display”, “OSCommerce Product Display”, 1, “OSCommerce Product Display”, “oscimp_admin”); should be add_options_page( ‘OSCommerce Product Display’, ‘OSCommerce Product Display’, ‘administrator’, ‘os_commerce_display_main’, ‘oscimp_admin’ ); Solution is untested. Docs: Roles and Capabilities, add_options_page The 3rd parameter is capability, not user level or whatever you were thinking. I set it to admin, see the docs on roles … Read more

Show add_meta_box by selecting a specific category

You could try this: get the ID’s of the attached categories and wrap your add_meta_box function inside a simple test against your defined cat ID. add_action(‘add_meta_boxes’, ‘is_in_cat_example’); function is_in_cat_example() { global $post; $category = ‘5’; // can be an array of ID’s as well if ( in_category( $category, $post ) ) { add_meta_box(…); } }

Default Plugin Settings Not Writing to Database

I believe the issue is that your function that sets up the settings initially isn’t getting run upon activation. Add a call to your mouldings_register_settings_initial() in the activation hook, like this: function mouldings_activate() { global $wpdb, $mouldings_options; mouldings_register_settings_initial(); if ($mouldings_options === false){ $mouldings_options = array( ‘idea_item_columns’ => ‘4’ ); update_option( ‘mouldings_settings’, $mouldings_options ); } } … Read more