Skip to content

Instantly share code, notes, and snippets.

@jdevalk
Last active August 9, 2016 21:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jdevalk/0f6bc1724e3b1162068e to your computer and use it in GitHub Desktop.
Save jdevalk/0f6bc1724e3b1162068e to your computer and use it in GitHub Desktop.
Small SEO plugin for GlotPress
<?php
class Yoast_GlotPress_SEO {
function __construct() {
add_filter( 'gp_title', array( $this, 'modify_title' ) );
add_action( 'gp_head', array( $this, 'meta_desc' ), 9 );
add_filter( 'gp_redirect_status', array( $this, 'modify_redirect_status' ), 10, 2 );
}
private function get_path() {
$url = gp_url_current();
$path = gp_url_path( $url );
return $path;
}
public function modify_title( $title ) {
if ( '/projects' == $this->get_path() ) {
return 'Translate Yoast Plugins to your language! • Yoast';
}
$title = preg_replace( '/&lt; GlotPress$/', '• Yoast Translate', $title );
return $title;
}
public function meta_desc() {
$path = $this->get_path();
$project = GP::$project->by_path( str_replace( '/projects/', '', $path ) );
$metadesc = '';
switch( $path ) {
case '/projects':
$metadesc = 'This the home of the Yoast Translate project, where all Yoast WordPress Plugins and Themes are being translated. Join today!';
break;
default:
if ( isset( $project ) && $project ) {
$metadesc = strip_tags( $project->description );
$metadesc = explode( "\n", $metadesc );
$metadesc = $metadesc[0];
}
break;
}
if ( $metadesc != '' ) {
echo '<meta name="description" content="'. esc_attr( $metadesc ) . '"/>'."\n\n";
}
}
public function modify_redirect_status( $status, $location ) {
if ( 302 == $status && '/projects' == $location ) {
return 301;
}
return $status;
}
}
$yoast_glotpress_seo = new Yoast_GlotPress_SEO();
@ramiy
Copy link

ramiy commented Nov 23, 2014

Very Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment