Set default featured image in Wordpress if none exists by Attachment ID

/** * Custom Footer * * @author Greg Rickaby * @since 1.0.0 */ function footer_output_filter( $output, $backtotop_text, $creds_text ) { $backtotop_text = '[footer_backtotop text="Top of Page"]'; $creds_text = 'Copyright [footer_copyright] <a href="'. trailingslashit( get_bloginfo('url') ) .'" title="'. esc_attr( get_bloginfo('name') ) .' rel="nofollow"">'.get_bloginfo('name').'</a><br>Built by <a href="http://internet-alacarte.com">Internet a la Carte</a> with <a href="http://my.studiopress.com/themes/education/">Education theme</a>'; $output = '<div class="creds">' . $creds_text . '</div>'; return $output; } /** * Plugin Name: Set featured image * Plugin URI: http://bueltge.de * Description: Set featureed image automaticly on save post/page * Version: 1.0.0 * Author: Frank Bültge * Author URI: http://bueltge.de * License: GPLv3 */ // This file is not called by WordPress. We don't like that. ! defined( 'ABSPATH' ) and exit; if ( ! function_exists( 'fb_set_featured_image' ) ) { add_action( 'save_post', 'fb_set_featured_image' ); function fb_set_featured_image() { if ( ! isset( $GLOBALS['post']->ID ) ) return NULL; if ( has_post_thumbnail( get_the_ID() ) ) return NULL; set_post_thumbnail( get_the_ID(), 260 ); } }
change the attachment ID, image is set on Save

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.