Summary
At activation time, the theme is loaded before your plugin, but after that the plugin is loaded first, so bracket the function in your plugin in the same way that the theme function is ‘plugged’
if !function_exists('pluggable_theme_function_name') {
function pluggable_theme_function_name () {
code here
}
}
Details
One is to use a child theme to overwrite a theme’s pluggable functions. BUT oh switching to a child theme is painful if one has done settings via the theme customizer. One has to re do the settings for the child theme. A better option I thought would be to define my own function to be used instead of the themes. But every time I tried to activate the plugin, it would tell me that the function was already defined. I thought I would have to resort to must-use plugin. Didn’t want to have to do that. I also wasn’t ready to redo my site., I was happy still using twenty-eleven theme.
Then for some reason I put “if ( ! function_exists( ‘twentyeleven_posted_on’ ) ) : ” before my function definition. It shoudn’t be necessary if my function was to be the one, it shouldn’t need that since it had to be defined first.
Lo and behold, then I could activate it, and once past the activation, it would work, I could even remove that line of code, and it would still work. It was only at activation time that the theme’s function was loaded before mine. The little plugin now looks like this:
<?php
/**
Plugin Name: amr adjust theme 2011
Author: anmari
Author URI: http://anmari.com/
Plugin URI: http://anmari.com
Version: 1.0
Description: Show 'Updated' and date last updated instead of published date
*/
if (!function_exists('twentyeleven_posted_on')) {
function twentyeleven_posted_on() {
$post = get_post();
$the_date = mysql2date( get_option( 'date_format' ), $post->post_modified );
$the_date_c = mysql2date( 'c', $post->post_modified );
printf(
__( '<span class="sep">Updated on </span><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a><span class="by-author"> <span class="sep"> by </span> <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'twentyeleven' ),
esc_url( get_permalink() ),
esc_attr( get_the_title() ),
esc_attr( $the_date_c ),
esc_html( $the_date ),
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( __( 'View all posts by %s', 'twentyeleven' ), get_the_author() ) ),
get_the_author()
);
}
}