How to add an admin function only to posts, not pages?

You can use post type conditional tag: if ( ‘post’ == get_post_type() ) Complete: function excerpt_count_js(){ if ( ‘post’ == get_post_type() ) { echo ‘<script>jQuery(document).ready(function(){ jQuery(“#postexcerpt .handlediv”).after(“<div style=\”position:absolute;top:0px;right:5px;color:#666;\”><small>Character limit = 150. Current characters: </small><input type=\”text\” value=\”0\” maxlength=\”3\” size=\”3\” id=\”excerpt_counter\” readonly=\”\” style=\”background:#fff;\”>&nbsp;</div>”); jQuery(“#excerpt_counter”).val(jQuery(“#excerpt”).val().length); jQuery(“#excerpt”).keyup( function() { jQuery(“#excerpt_counter”).val(jQuery(“#excerpt”).val().length); }); });</script>’; } return; } add_action( ‘admin_head-post.php’, ‘excerpt_count_js’); add_action( … Read more

Posts Page Featured Image [closed]

I feel like such an idiot!! I was trouble-shooting this last night and I guess I removed the featured image for the news page…so, of course, the image wasn’t showing up! I added the featured image and the following code: <?php if(is_home()) { ?> <?php $page_for_posts = get_option( ‘page_for_posts’ ); echo get_the_post_thumbnail($page_for_posts, ‘large’); ?> <?php … Read more

How to display an icon when a new post is published and then remove it when a specific time past?

Filter the content of post_class(): add_filter( ‘post_class’, function( $classes ) { if ( is_singular() ) return $classes; // now minus last mod time in seconds $diff = time() – mysql2date( ‘U’, $post->post_date ); if ( DAY_IN_SECONDS <= $diff ) $classes[] = ‘new-post’; return $classes; }); Now, in your loop, use post_class(), and you get an … Read more

Custom colors for post rows based on post meta value

If your theme uses wp post class function post_classes($classes) { global $post; $customMetaVariable = get_post_meta( $post->ID, ‘customMetaName’, true ); if($customMetaVariable == ‘desiredCustomMetaValue’){ $classes[] = ‘cssClassName’; return $classes; } } add_filter(‘post_class’, ‘post_classes’); then in your style.css you could use: .cssClassName{ background-color: red; } hence applying that class to all of the posts that contain your desired … Read more

How can I export and then import posts with featured images?

You can consult this answer, but the instructions are a bit unclear, so I’ll clarify them myself here. On the old blog, export the posts using the standard WordPress import/export functionality. If you’re unfamiliar with that, see this link for more information: https://codex.wordpress.org/Importing_Content On the new blog, use the WP Importer to import the XML … Read more

Get how many days since last post of the current user

You can use a modified version of this answer by @s_ha_dum. Where instead of an option you can setup a user meta (even if meta query is slower than option query) add_action(‘save_post’, ‘user_last_update’, 10, 2); function user_last_update($id, $p) { if ( (defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE) || (defined(‘DOING_AJAX’) && DOING_AJAX) || ($p->post_status !== ‘publish’) ) { return; … Read more

Post custom permalink results in 404 for archive page

You can override the Post type object settings in the init action and register the proper values for the archive and rewrites: add_action(‘init’, ‘my_init’); function my_init() { $args = objectToArray( get_post_type_object(‘post’) ); $args[‘has_archive’] = ‘news’; $args[‘rewrite’] = array( ‘slug’ => ‘news’, ‘with_front’ => FALSE, ); register_post_type(‘post’, $args); } function objectToArray( $object ) { if( !is_object( … Read more