Last active
September 15, 2024 02:08
-
-
Save rveitch/dd88735622ef597c74e8 to your computer and use it in GitHub Desktop.
A simple plugin starter template to add extra info to posts excerpt previews, after the excerpt-content.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin name: WordPress Plugin Template - Extra Post Info | |
Plugin URI: http://veitchdigital.com/ | |
Description: A simple plugin starter template to add extra info to posts excerpt previews, after the excerpt-content. | |
Author: Ryan Veitch | |
Author http://veitchdigital.com/ | |
Version: 0.1 | |
*/ | |
// Call extra_post_info_menu function to load plugin menu in dashboard | |
add_action( 'admin_menu', 'extra_post_info_menu' ); | |
// Create WordPress admin menu | |
function extra_post_info_menu(){ | |
$page_title = 'WordPress Extra Post Info'; | |
$menu_title = 'Extra Post Info'; | |
$capability = 'manage_options'; | |
$menu_slug = 'extra-post-info'; | |
$function = 'extra_post_info_page'; | |
$icon_url = 'dashicons-info'; | |
$position = 4.01; // Use decimal places to avoid position conflicts | |
add_menu_page( $page_title, | |
$menu_title, | |
$capability, | |
$menu_slug, | |
$function, | |
$icon_url, | |
$position ); | |
// Call update_extra_post_info function to update database | |
add_action( 'admin_init', 'update_extra_post_info' ); | |
} | |
// Create function to register plugin settings in the database | |
function update_extra_post_info() { | |
register_setting( 'extra-post-info-settings', 'extra_post_info' ); | |
} | |
// Create Dashboard plugin page | |
function extra_post_info_page(){ | |
?> | |
<h1>Extra Post Info Settings</h1> | |
<form method="post" action="options.php"> | |
<?php settings_fields( 'extra-post-info-settings' ); ?> | |
<?php do_settings_sections( 'extra-post-info-settings' ); ?> | |
<table class="form-table"> | |
<tr valign="top"> | |
<th scope="row">Extra post info:</th> | |
<td><input type="text" name="extra_post_info" value="<?php echo get_option('extra_post_info'); ?>"/></td> | |
</tr> | |
</table> | |
<?php submit_button(); ?> | |
</form> | |
<?php | |
} | |
// Plugin logic for adding extra info to posts | |
if( !function_exists("extra_post_info") ) | |
{ | |
function extra_post_info($content) | |
{ | |
$extra_info = get_option('extra_post_info'); | |
return $content . $extra_info; | |
} | |
// Apply the extra_post_info function on our content | |
add_filter('the_content', 'extra_post_info'); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment