Change Default Image HTML

This will do: <?php /* * This filter only works with images, for all kind of media check: media_send_to_editor * The priority is set to 20 and it takes 8 arguments */ add_filter(‘image_send_to_editor’, ‘wpse_53577_img_wrapper’, 20, 8); // We are only working with the $html argument, but you can play with all of them function wpse_53577_img_wrapper($html, … Read more

Current theme broken – after server and domain migration

Try the XCloner plugin: http://wordpress.org/extend/plugins/xcloner-backup-and-restore/. I use XCloner to move sites between my live server and my dev server. It takes care of all the migration differences between the domain, database, etc. It preserves all my widget settings, custom menus, etc.

Post X of Y in single.php / sidebar.php

class MY_Post_Numbers { private $count = 0; private $posts = array(); public function display_count() { $this->init(); // prevent unnecessary queries $id = get_the_ID(); echo sprintf( ‘<div class=”post-counter”>Post number<span class=”num”>%s</span><span class=”slash”>/</span><span class=”total”>%s</span></div>’, $this->posts[$id], $this->count ); } private function init() { if ( $this->count ) return; global $wpdb; $posts = $wpdb->get_col( “SELECT ID FROM $wpdb->posts WHERE post_status=”publish” … Read more

switch a theme different per user role

There’s current_user_can( ‘CAPABILITY’ ); (see @Codex Users & Roles to find the appropriate cap for your targeted role), that you can use to determin what theme you want to display. You can also check for is_user_logged_in() if you just want to differentiate between non-logged in and logged in users. Then you have the switch_theme() function. … Read more

Making the Header on the Twenty Ten Theme Less Tall?

To make the header on the Twenty Ten theme less tall (i.e. a height with fewer pixels) put this code at the bottom of your theme’s “functions.php” file (being sure to change the number 180 to whatever height you want): <?php add_action(‘twentyten_header_image_height’,’yoursite_header_image_height’); function yoursite_header_image_height($height) { return 180; // Modify this to whatever pixel height you … Read more

How to avoid loading style.css twice in child-theme?

You usually don’t need to enqueue a child theme’s stylesheet. The parent theme does that. This is a bit confusing, so I’ll explain. In most themes, Twenty Seventeen included, the stylesheet is loaded like this: wp_enqueue_style( ‘twentyseventeen-style’, get_stylesheet_uri() ); The trick to understanding what’s going on here is understanding what get_stylesheet_uri() does. When a regular … Read more

Copying theme from Localhost to Live does not copy all theme settings with it?

Since I found this script, I have used it for every single move I make from Localhost to Live or vice versa. It’s incredibly simple to use and has worked every time. https://github.com/interconnectit/Search-Replace-DB (Review: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/ ) From their site: You must use a safe search and replace method that preserves the integrity of the serialized … Read more