-
-
Save remkus/fd7d1ce7c2fbf83399fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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( '/< 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment