Add Adsense code in index.php

Here is a slight variation of my other answer. First we register two new widget areas, sidebars in WordPress-speak. add_action( ‘widgets_init’, ‘wpse_84250_register_ad_widgets’ ); function wpse_84250_register_ad_widgets() { // used on the first page of main loop only register_sidebar( array ( ‘name’ => ‘Ad Widget 1’, ‘id’ => ‘ad_widget_1’, ‘before_widget’ => ‘<div class=”frontpage-ads”>’, ‘after_widget’ => ‘</div>’ ) … Read more

Prevent multiple counts by same user – WP PostViews plugin

Since the plugin author does not offer any actions or filters for us to hook onto, we’ll have to settle for “listening” to changes to the views meta field instead. function wpse_104324_prevent_multiple_views( $meta_id, $object_id, $meta_key, $meta_value ) { if ( $meta_key === ‘views’ ) { if ( ! empty( $_COOKIE[ USER_COOKIE . ‘_views’ ] ) … Read more

Meta Query “IN” doesn’t work with ACF checkbox filter

Checkbox field is stored as serialized array, therefore you can not use the IN operator and array with the values you are looking for. To get posts with checked “melbourne”, change meta_query to: $meta_query = array( array( ‘key’ => $name, ‘value’ => ‘”melbourne”‘, ‘compare’ => ‘LIKE’, ) ); To get posts with melbourne or sydney: … Read more

Get post meta in enqueued js file

You can send variables to your script with wp_localize_script: wp_enqueue_script( ‘some_handle’ ); global $post; $my_meta = get_post_meta( $post->ID, ‘my_meta’, true ); $array = array( ‘my_meta’ => $my_meta ); wp_localize_script( ‘some_handle’, ‘object_name’, $array ); You can then use the var in your script like: object_name.my_meta

Save selected item from dropdown menu in a meta box as a metadata value for a custom post type

$myterms = get_terms($taxonomies, $args); returns an array of term objects. Use $term->term_id as option value … “<option value=”$term->term_id”>”. esc_html( $term_name ) . “</option>” … and store that ID, not the name. Names can change, the IDs will stay the same – unless someone deletes a term and creates a new one with the same name. … Read more