How to add an admin function only to posts, not pages?

You can use post type conditional tag: if ( ‘post’ == get_post_type() ) Complete: function excerpt_count_js(){ if ( ‘post’ == get_post_type() ) { echo ‘<script>jQuery(document).ready(function(){ jQuery(“#postexcerpt .handlediv”).after(“<div style=\”position:absolute;top:0px;right:5px;color:#666;\”><small>Character limit = 150. Current characters: </small><input type=\”text\” value=\”0\” maxlength=\”3\” size=\”3\” id=\”excerpt_counter\” readonly=\”\” style=\”background:#fff;\”>&nbsp;</div>”); jQuery(“#excerpt_counter”).val(jQuery(“#excerpt”).val().length); jQuery(“#excerpt”).keyup( function() { jQuery(“#excerpt_counter”).val(jQuery(“#excerpt”).val().length); }); });</script>’; } return; } add_action( ‘admin_head-post.php’, ‘excerpt_count_js’); add_action( … Read more

Custom colors for post rows based on post meta value

If your theme uses wp post class function post_classes($classes) { global $post; $customMetaVariable = get_post_meta( $post->ID, ‘customMetaName’, true ); if($customMetaVariable == ‘desiredCustomMetaValue’){ $classes[] = ‘cssClassName’; return $classes; } } add_filter(‘post_class’, ‘post_classes’); then in your style.css you could use: .cssClassName{ background-color: red; } hence applying that class to all of the posts that contain your desired … Read more

How to show custom field’s value under post/page title in wp-admin

Just like you add new columns you render the title filed your self add_action( ‘manage_posts_custom_column’, ‘admin_post_data_row’, 10, 2); function admin_post_data_row($column_name, $post_id) { switch($column_name){ case ‘title’: edit_post_link(get_post_title($post_id), ‘<p>’, ‘</p>’,$post_id); echo ‘<br />’.get_post_meta($post_id,’field_name’,true); break; default: break; } } and if you have another plugin cancels this then simply set the filter hook priority to something bigger.

Disable collapse of admin meta boxes

Add this to your functions file and it will kill the metabox toggles: function kill_postbox(){ global $wp_scripts; $footer_scripts = $wp_scripts->in_footer; foreach($footer_scripts as $key => $script){ if(‘postbox’ === $script) unset($wp_scripts->in_footer[$key]); } } add_action(‘admin_footer’, ‘kill_postbox’, 1);

Reference external file as a function

You can’t. Create a function that loads that file: function load_admin_page_file() { require ‘admin-members.php’; } Then use that function name as callback argument. In PHP 5.3 you can use a lambda: add_menu_page( ‘Members’, ‘Members’, ‘manage_options’, ‘members’, function() { require ‘admin-members.php’; } );

How do you modify CSS files via admin panel?

If you’re wanting styles to be dynamic, then you’ll have to emit your CSS file as you are suggesting. However, as WordPress often uses styles.css as a theme definition file, renaming styles.php might cause problems. It might be better to collect all the ‘dynamic’ definitions into a separate file (eg dynamic-styles.php) and import them from … Read more

Permalinks not working (.htaccess is writable)

Have you tried something simple to ensure it is actually rewriting? Something like… RewriteEngine On RewriteRule ^.*$ verified.php Then create a verified.php page… <?php print ‘mod_rewrite works!’; ?> Now you should hit that page no matter where you try to go on the site. If you don’t mod_rewrite isn’t working. You can also turn on … Read more