Quantcast
Viewing all articles
Browse latest Browse all 12

WordPress Changing Pluggable Functions Without Child Theme

A new concept (?) – to change a pluggable function of a WordPress theme without creating a child theme.

Example – to remove the  post tags output from the posts of Twenty Twelve.

Often, these things can be done by editing the styles of the theme, however in this case, CSS would not work as the tags don’t have their own CSS class.

Creating a child theme is usually recommended as the easiest option; but this might be over the top if the only changed paremeters are from some pluggable functions.

The alternative way would be to create a plugin to alter (in this example) the post-meta-data output, which is done through the function ‘twentytwelve_entry_meta()’.

How to:
use FTP to create a file, for example with the file name twentytwelve-entry-meta-modified.php, in the /wp-content/plugins/ folder; and add this example code (http://pastebin.com/7dMVvC9E)

<?php
/*
Plugin Name: Entry Meta Twenty Twelve Modified
Plugin URI: n/a
Description: personalization of the entry meta of Twenty Twelve without child theme; in this particular example the removal of the tags.
Version: 1.0
Author: alchymyth
Author URI: http://transformationpowertools.com
License: GPL2
*/

add_action( 'setup_theme', 'modify_pluggable_theme_functions' );

function modify_pluggable_theme_functions() {

if( wp_get_theme() == 'Twenty Twelve' && get_stylesheet_directory() == get_template_directory() ) :
//check for the right theme and that no child theme is used
function twentytwelve_entry_meta() {
// Translators: used between list items, there is a space after the comma.
$categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );

$date = sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time datetime="%3$s">%4$s</time></a>',
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() )
);

$author = sprintf( '<span><a href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
get_the_author()
);

if ( $categories_list ) {
$utility_text = 'This entry was posted in %1$s on %2$s<span> by %3$s</span>.';
} else {
$utility_text = 'This entry was posted on %2$s<span> by %3$s</span>.';
}

printf(
$utility_text,
$categories_list,
$date,
$author
);
}
endif;
}
?>

The code checks that Twenty Twelve is the active theme, and that no child theme is activated.

Activate the plugin ‘Entry Meta Twenty Twelve Modified’ as usual from within dashboard – plugins.

http://codex.wordpress.org/Pluggable_Functions
http://codex.wordpress.org/FTP_Clients
http://codex.wordpress.org/Plugins
http://codex.wordpress.org/Writing_a_Plugin
http://codex.wordpress.org/Plugin_API/Action_Reference


Viewing all articles
Browse latest Browse all 12

Trending Articles