How to get the ID of an item in an audio playlist?

We don’t have an explicit filter for the data array so here are two workarounds that you might give a try: Approach #1 – As meta data We can add attachment_id to the meta data for each playlist item, via the wp_get_attachment_metadata filter, but first we have to register it via the wp_get_attachment_id3_keys filter. Here’s … Read more

Enqueue Javascript Correctly for 3.5

Never de-register core-bundled scripts in the WP-Admin. You shouldn’t do it on the front end, either, unless you really, really know what you’re doing. But especially in the WP-Admin, just use the core-bundled scripts. Also, when you use core-bundled jQuery UI, WordPress already knows that jQuery is a dependency. Just change the first callback to … Read more

count number of user comments with a specific comment meta value

Your basic question is a pure SQL question. $count = $wpdb->get_var( ‘SELECT COUNT( comments.comment_ID ) FROM ‘. $wpdb->comments .’ as comments LEFT JOIN ‘.$wpdb->commentmeta.’ AS cmeta ON comments.comment_ID = cmeta.comment_id WHERE user_id = 1 AND comment_approved = “1” AND comment_type NOT IN (“pingback”, “trackback” ) AND cmeta.meta_key = “rating” AND cmeta.meta_value = 5′ ); I … Read more

How To Customize Position of »add to cart« of WooCommerce on Product Page [closed]

You can do what you want by hooking into the woocommerce_single_product_summary action. The action is executed inside content-single-product.php like this: <?php /** * woocommerce_single_product_summary hook * * @hooked woocommerce_template_single_title – 5 * @hooked woocommerce_template_single_price – 10 * @hooked woocommerce_template_single_excerpt – 20 * @hooked woocommerce_template_single_add_to_cart – 30 * @hooked woocommerce_template_single_meta – 40 * @hooked woocommerce_template_single_sharing – … Read more

Ajax template: how to handle head section

Ok, you want that mobile devices always load mobile templates. Desktop devices load template files based on resolution: if < 1080 mobile ones, > 1080 desktop ones. Your workflow should be: On init you check for mobile devices using wp_is_mobile. If true you add a template filter that returns str_replace(‘.php’, ‘-mobile.php’, $template); where $template is … Read more

class=”parent” for wp_list_pages?

Phew! Bit more complex than I would’ve liked – if only the filter page_css_class passed back $args it would save a lot of effort (may submit this to trac). Since 3.3 it’s as easy as this! function add_parent_class( $css_class, $page, $depth, $args ) { if ( ! empty( $args[‘has_children’] ) ) $css_class[] = ‘parent’; return … Read more

Transform php code into a widget?

Here is a stand-alone answer. Building a widget to echo hard-coded PHP is trivial. class PHP_Widget_wpse_80256 extends WP_Widget { function __construct() { $opts = array( ‘description’ => ‘Display Some Hard Coded PHP content’ ); parent::WP_Widget( ‘my-hc-php-content’, ‘Some PHP’, $opts ); } function widget($args,$instance) { // PHP goes here, like this: echo ‘PHP generated content’; } … Read more

Counting number of posts in a category and its sub categories and displaying result using shortcode

The shortcode // Add Shortcode to show posts count inside a category function category_post_count( $atts ) { $atts = shortcode_atts( array( ‘category’ => null ), $atts ); // get the category by slug. $term = get_term_by( ‘slug’, $atts[‘category’], ‘category’); return ( isset( $term->count ) ) ? $term->count : 0; } add_shortcode( ‘category_post_count’, ‘category_post_count’ ); Usage … Read more

How to Use the Function is_user_logged_in To Display Different Menus?

i just did this for a site i am working on. first i registered 2 menus in functions.php: add_action(‘init’,’kia_menus’); function kia_menus(){ register_nav_menus( array(‘primary-menu’ => __( ‘Primary Menu for Logged In Users’, ‘kia_theme’ ), ‘primary-loggedout’ => __( ‘Primary Menu for Logged Out Visitors’, ‘kia_theme’) )); } and then where i want the 1 menu to appear … Read more