customizing recent posts

Inside your post loop: <div class=”recent-post”> <div class=”thumbnail”> <?php if(has_post_thumbnail()) { the_post_thumbnail(); } else { // show a default image if no featured image is specified echo ‘<img src=”‘.get_bloginfo(“template_url”).’/images/img-default.png” />’; } ?> </div> <div class=”title”> <a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a> </div> </div> float the thumbnail div to the left and give the title div … Read more

How do I register a stylesheet inside a WordPress widget?

wp_enqueue_scripts is called way before WordPress processes the widget content, so just as in this post, you’ve missed the boat :). Instead, just call wp_enqueue_style directly: function widget($args, $instance) { wp_enqueue_style( ‘myprefix-style’, plugins_url(‘mystyle.css’, __FILE__) ); //Widget content } (no need to register if you’re just going to enqueue it straight after). Same works for wp_enqueue_script.

I need to generate the CSS for my plugin from a function, how do i map a request to a function in the front-end?

This is forked from something I wrote for a similar requirement. empty( $_GET[‘my-css-var’] ) || add_action( ‘plugins_loaded’, ‘wpse_59089_css’ ); function wpse_59089_css() { header( ‘Content-Type: text/css’ ); // Aggressive caching to save future requests from the same client. $etag = ‘”‘ . md5( __FILE__ . $_GET[‘my-css-var’] ) . ‘”‘; header( ‘ETag: ‘ . $etag ); header( … Read more

TwentyTwelve versioning

How it’s NOT done in WordPress The following example is the opposite of how one should do it. Bad practice following: <style type=”text/css”> <!– /* … Definitions that are hard to override or get rid off are here … */ –> </style> This is another example how you should not do it: <link rel=”stylesheet” type=”text/css” … Read more

wordpress with many custom styled static pages

You can make each one into a custom Page Template, and either add the style block directly in the template, or conditionally load a stylesheet based on which template is in use. This will let you still use the editor to change the content of the page, but involves a lot of “one-off” page management. … Read more

Deregister CSS style link ‘open-sans-css’

WP Core actually uses Open Sans font; it’s not a plugin. there is a plugin that removes it, but you can probably simply dequeue or deregister it. adding this to functions.php should work; if you want it removed from the backend as well, hook into the admin_print_styles action. function dequeue_opensans_css() { wp_dequeue_style( ‘open-sans’ ); } … Read more

wp_head() not inserting the default stylesheet style.css

Actually you shouldn’t add JS and CSS files to your header.php, but make use of the functions wp_enqueue_script() and wp_enqueue_style() to add them there. Example taken from the codex page: /** * Proper way to enqueue scripts and styles */ function theme_name_scripts() { wp_enqueue_style( ‘style-name’, get_stylesheet_uri() ); wp_enqueue_script( ‘script-name’, get_template_directory_uri() . ‘/js/example.js’, array(), ‘1.0.0’, true … Read more