Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Create optimize.php #185

Closed
wants to merge 1 commit into from

3 participants

@kvnol

Do not know if they will accept, but I created a file and put together some code that cleans the and do some basic SEO settings, without having to use some plugins. I think it would be cool to add _s, hopefully accept. ;)

@kvnol kvnol Create optimize.php
 Optimizations cleaning <head> and SEO

To added this file, and optimize your theme, just add a require_once in functions.php.

Like this:
 require_once get_template_directory() . '/inc/optimize.php';
d6aae6f
@kvnol

I understand, but do the other actions of removal can not be used?

@obenland
Owner

This looks more like plugin territory to me. It has nothing to do with defining the front-end display of content, really.

@kvnol

Yeah, it would be redundant to have this file and optimize a plugin that execute the same actions on WordPress. But it will only execute if the called functions.

Anyway, we'll see. ;)

@sixhours
Owner

I agree, this is plugin territory, not appropriate for a starter theme.

@kvnol kvnol closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 19, 2013
  1. @kvnol

    Create optimize.php

    kvnol authored
     Optimizations cleaning <head> and SEO
    
    To added this file, and optimize your theme, just add a require_once in functions.php.
    
    Like this:
     require_once get_template_directory() . '/inc/optimize.php';
This page is out of date. Refresh to see the latest.
Showing with 85 additions and 0 deletions.
  1. +85 −0 inc/optimize.php
View
85 inc/optimize.php
@@ -0,0 +1,85 @@
+<?php
+/**
+ * Optimizations cleaning <head> and SEO.
+ *
+ * To added this file, and optimize your theme, just add a require_once in functions.php.
+ *
+ * Like this:
+ * require_once get_template_directory() . '/inc/optimize.php';
+ *
+ * @package _s
+ * @since _s 1.0
+ */
+
+/**
+ * Cleanup wp_head().
+ */
+function _s_head_cleanup() {
+ // category feeds.
+ // remove_action( 'wp_head', 'feed_links_extra', 3 );
+ // post and comment feeds.
+ // remove_action( 'wp_head', 'feed_links', 2 );
+ // EditURI link.
+ remove_action( 'wp_head', 'rsd_link' );
+ // windows live writer.
+ remove_action( 'wp_head', 'wlwmanifest_link' );
+ // index link.
+ remove_action( 'wp_head', 'index_rel_link' );
+ // previous link.
+ remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
+ // start link.
+ remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
+ // links for adjacent posts.
+ remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
+ // WP version.
+ remove_action( 'wp_head', 'wp_generator' );
+}
+
+add_action( 'init', '_s_head_cleanup' );
+
+/**
+ * Remove WP version from RSS.
+ */
+function _s_version() {
+ return '';
+}
+
+add_filter( 'the_generator', '_s_rss_version' );
+
+/**
+ * Add rel="nofollow" and remove rel="category"
+ */
+function _s_modify_category_rel( $text ) {
+ $search = array( 'rel="category"', 'rel="category tag"' );
+ $text = str_replace( $search, 'rel="nofollow"', $text );
+ return $text;
+}
+
+add_filter( 'wp_list_categories', '_s_modify_category_rel' );
+add_filter( 'the_category', '_s_modify_category_rel' );
+
+/**
+ * Add rel="nofollow" and remove rel="tag"
+ */
+function _s_modify_tag_rel( $taglink ) {
+ return str_replace( 'rel="tag">', 'rel="nofollow">', $taglink );
+}
+
+add_filter( 'wp_tag_cloud', '_s_modify_tag_rel' );
+add_filter( 'the_tags', '_s_modify_tag_rel' );
+
+/**
+ * Add feed link
+ */
+add_theme_support( 'automatic-feed-links' );
+
+/**
+ * Remove ?ver=***
+ */
+function _s_remove_cssjs_ver( $src ) {
+ if( strpos( $src, '?ver=' ) )
+ $src = remove_query_arg( 'ver', $src );
+ return $src;
+}
+add_filter( 'style_loader_src', '_s_remove_cssjs_ver', 10, 2 );
+add_filter( 'script_loader_src', '_s_remove_cssjs_ver', 10, 2 );
Something went wrong with that request. Please try again.