Add stylesheets and js to template files when shortcode is used

put wp_enqueue_script() in your shortcode handler. add_shortcode(‘myshortcode’, ‘my_shortcode_handler’); function my_shortcode_handler($atts) { wp_enqueue_script(‘my-script’, plugins_url(‘my-script.js’, __FILE__), array(‘jquery’), ‘1.0’, true); // actual shortcode handling here return “bacon flavored shortcode here”; } this definitely loads the my-script.js file for me. it gets loaded in the footer though. i don’t think there is a way for it to load conditionally … Read more

Targeting a Certain Post in Loop (CSS)

They key is here: <li <?php post_class(); ?> id=”post-<?php the_ID(); ?>”> You can add a parameter to the post_class call, e.g.: $counter = 0; $custom_query = new WP_Query(‘cat=2687&posts_per_page=3’); //Top of the page – Top Photo Category while($custom_query->have_posts()) : $custom_query->the_post(); $counter++; $column = $counter %3; // 3 columns, use module to get the remainder $class = … Read more

Extending body classes in front- and backend

Your snippet adds the following classes to the body tag on the front end, someText someText Your snippet adds the following classes to the body tag on the back end, someClassA someClassB If that is you intended result, then yes that works and is correct. You could also do, function add_custom_body_classes($classes) { $someClassA = ‘someText’; … Read more

Layer post title on top of image WordPress featured thumbnail image

the_post_thumbnail() does not return the path of your image. Instead, it returns the complete HTML markup for that image. You can use this instead: $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ) ); echo $image[0]; If you want a specific size you can pass an additional parameter: $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘full’ ); echo $image[0]; … Read more

Hiding styles from Facebook

You can use Open Graph Protocol to define the data Facebook fetches from your site: http://developers.facebook.com/docs/opengraphprotocol/ The metatag for the description has this form: <meta property=”og:description” content=”my custom description for single post” /> You can use plugins, like http://wordpress.org/extend/plugins/wp-facebook-open-graph-protocol/ to do it for you. You can then debug your page here: http://developers.facebook.com/tools/debug to see how … Read more