Closed cconover closed 9 years ago
I know that if I needed to add any features to my theme, I would need to use child themes and modify the functions.php file. From there I can filter output and do whatever I needed.
But after installing a plugin that lets me add actions and filters to my WP install, then I don't even need a child theme. I just added my functions there.
I learned all this when I was investigation hAtom feeds, here are those functions I needed to add:
//mod content
function hatom_mod_post_content ($content) {
if ( in_the_loop() && !is_page() ) {
$content = '<span class="entry-content">'.$content.'</span>';
}
return $content;
}
add_filter( 'the_content', 'hatom_mod_post_content');
//add hatom data
function add_mod_hatom_data($content) {
$t = get_the_modified_time('F jS, Y');
$author = get_the_author();
$title = get_the_title();
if ( is_single() || is_page()) {
$content .= '<div class="hatom-extra" style="display:none;visibility:hidden;"><span class="entry-title">'.$title.'</span> was last modified: <span class="updated">'.$t.'</span> by <span class="author vcard"><span class="fn">'.$author.'</span></span></div>';
}
return $content;
}
add_filter('the_content', 'add_mod_hatom_data');
I hope this helps somewhat. I'm thinking something similar will need to be done - have your plugin interact with WP theme functions.
I looked at the files of that plugin, and it is quite big on JavaScript. Plugins name is Add Actions and Filters.
Yeah, that was my thought. I need to look into all possible functions that can be used to render the featured image in a theme, and filter them to append the HTML for the caption.
Just tried out your update, pretty nice to see it working. I do have one more request (this may need its own issue opened). Take a look at how my theme display the featured image on my website. This applies to any other pages with a featured image. See where I have the featured image caption (towards the bottom of the page).
I use a plugin to create a shortcode with the following:
echo "<p><i>Featured Image Credit: </i></p>"; cc_featured_image_caption();
I then insert the shortcode [featuredImageCaption] at the end of my posts and get the results you see.
Any way to have this functionality built-in since the groundwork is in place (from what I have seen of the current build) to have an additional shortcode for those that want to have the featured image caption separate from the image?
It's funny you mention that, I was literally just thinking about 20 minutes ago of adding a shortcode.
Yeah, go ahead and open a new issue on it so it can be tracked separately.
Awesome! I will go ahead and open the issue with as much detail as I can.
Look into the option for the plugin to modify the function that renders the featured image in a theme to append the featured image caption HTML to the featured image HTML. This would remove the need to modify theme code, and make installation and usage simpler for non-technical users.