Show dialog box in TinyMCE plugin and use WordPress php functions in it

Instead of requireing admin.php you just can use WP built-in ajax functionality, even if it’s not ajax in this case. Add a hook add_action(‘wp_ajax_my_plugin_function’, ‘my_plugin_function_callback’); Create your output function (callback) function my_plugin_function_callback() { // do stuff } Call it this way instead of: file : url + ‘/box.php’, you should be able to use the … Read more

Style every second widget?

Use the dynamic_sidebar_params filter. The following code adds classes to say whether the widget is odd or even, what index it is in the sidebar, and what sidebar it’s in. Note: the str_replace(“class=\””, “class=\”$class “, $before_widget); code below depends on your before_widget using double quotes — it probably should be done with a regular expression … Read more

PHP if Condition not working

You should be using the “AND” operator, not “OR” <?php if (!is_page(‘about-us’) && !is_page(‘news-articles’)) {wp_head();}?> Because you want to display the WP head only if both conditions are true.

How to break down importing of feeds

You can try using wp cron functions, programing a feed import every 10 minutes or so, until you have nothing left in queue. Example code: <?php register_activation_hook( __FILE__, ‘wp1903_schedule_cron’ ); function wp1903_schedule_cron() { $counter = 0; $feeds = array( ‘http://example.com/feed1’, ‘http://example.com/feed2’, ‘http://example.com/feed3’, ‘http://example.com/feed4’ ); foreach ($feeds as $feed) { $counter++; // schedule every 10 mins … Read more

Highlight Current Tag in wp_tag_cloud

When you are in a tag template, a body class is added with term-{termID}, so you can hook in “wp_generate_tag_cloud_data” to check if class is present and add custom class to the tag 😉 function tribalpixel_tag_cloud_class_active($tags_data) { $body_class = get_body_class(); foreach ($tags_data as $key => $tag) { if(in_array(‘term-‘.$tag[‘id’], $body_class)) { $tags_data[$key][‘class’] = $tags_data[$key][‘class’] .” active-tag”; … Read more

WordPress get pagination on wpdb get_results

You say “However, I know this is not a good way to do this” in your self answer. One thing I could add answering your question and using your answer is, you can use SQL_CALC_FOUND_ROWS with $wpdb $result = $wpdb->get_results( “SELECT SQL_CALC_FOUND_ROWS * FROM `wp_table` WHERE 1 LIMIT 10;” ); $total_count = $wpdb->get_var( “SELECT FOUND_ROWS();” … Read more

enqueue multiple Google fonts with multiple weights and styles (italic)

Adding Multiple Google fonts in WordPress Standard Way function adding_theme_css_js(){ wp_enqueue_style(“adding-google-fonts”, all_google_fonts()); } add_action(“wp_enqueue_scripts”,”adding_theme_css_js”); function all_google_fonts() { $fonts = array( “Open+Sans:400,300”, “Raleway:400,600” ); $fonts_collection = add_query_arg(array( “family”=>urlencode(implode(“|”,$fonts)), “subset”=>”latin” ),’https://fonts.googleapis.com/css’); return $fonts_collection; }

Check if term object is in array

WordPress has the wp_list_pluck function, which can be helpful here. We can make an array of just term IDs from the array of objects like: $term_ids = wp_list_pluck( $subcat_terms, ‘term_id’ ); Then we can check in_array: $this_id = 42; if( in_array( $this_id, $term_ids ) ){ // do something }

Use is_product_category() properly

is_product_category() is to be used on woocommerce category archive pages only so first make sure that you are on category archive. instead of category number use category slug name is_product_category(‘category-slug’) no need to run OR(||) condition just use is_product_category(‘category-slug1′,’category-slug2’) to get same output

Styling images coming from another blog

Calling image_resize() would be difficult, since it would search for the image in your main blog’s upload directory. If it is a fixed image size I would just add it to the configuration of your photoblog, so it is created there when you upload new images (you can then rebuild your old image thumbnails). In … Read more