Check if first paragraph is an image, then show custom code right after it?

How about a few simple lines With jQuery? jQuery(document).ready( function ($) { if ($(“.entry-content:first-child”).has(‘img’).length) //this check for the img tag $(“.entry-content:first-child”).after(“<div>MY CUSTOM CODE</div>”); else $(“.entry-content:first-child”).before(“<div>MY CUSTOM CODE</div>”); }); Update: Here is a simple solution using php’s native DOMDocument add_filter(‘the_content’,’add_code_before_afterImage’); function add_code_before_afterImage($content){ $MYCODE = ‘<div>this is my custom code</div>’; $doc = new DOMDocument(); @$doc->loadHTML(‘<?xml encoding=”‘.get_bloginfo(‘charset’).'”>’.$content); $ps … Read more

how to create a conditional content_width for a wordpress theme?

No, its not possible. $content_width is a theme-wide constant, and its set in functions.php before any of the query conditionals are set. $content_width is used to determine the intermediate image sizes in image_send_to_editor. The “large” image size will be set to the value of $content_width. If you need to modify those sizes on a per-category … Read more

Loading scripts only if a particular shortcode or widget is present

You can use the function is_active_widget . E.g.: function check_widget() { if( is_active_widget( ”, ”, ‘search’ ) ) { // check if search widget is used wp_enqueue_script(‘my-script’); } } add_action( ‘init’, ‘check_widget’ ); To load the script in the page where the widget is loaded only, you will have to add the is_active_widget() code, in … Read more

wp enqueue style on specific page templates

If you plan to do a lot of WP development you should bookmark this page: http://codex.wordpress.org/Conditional_Tags The other answer works but the conditional relies upon your page slug (myurl.com/this-is-the-slug) never changing. A more reliable method (IMO), and one that fits this case, would be to use the is_page_template(‘example-template.php’) conditional check instead.