Last active
May 28, 2018 18:27
-
-
Save wpmudev-sls/7265c353292919d88e4bf2f24fe9a3ca to your computer and use it in GitHub Desktop.
SmartCrawl Title and Description fix for Extra theme on Home page
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 | |
/** | |
* Plugin Name: SmartCrawl Title and Description fix for Extra theme | |
* Plugin URI: https://premium.wpmudev.org/ | |
* Description: SmartCrawl Title and Description fix for Extra theme | |
* Author: Ariful Islam @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org/profile/itsarifulislam | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
if ( ! class_exists( 'SmartCrawlTitleDescriptionFixForExtraTheme' ) ) { | |
class SmartCrawlTitleDescriptionFixForExtraTheme { | |
private static $_instance = null; | |
public $title = null; | |
public $description = null; | |
public static function get_instance() { | |
if ( is_null( self::$_instance ) ) { | |
self::$_instance = new SmartCrawlTitleDescriptionFixForExtraTheme(); | |
} | |
return self::$_instance; | |
} | |
private function __construct() { | |
if ( ! defined('SMARTCRAWL_PLUGIN_DIR') ) return; | |
$resolver_path = SMARTCRAWL_PLUGIN_DIR . '/core/class_wds_endpoint_resolver.php'; | |
if ( ! class_exists('Smartcrawl_Endpoint_Resolver') && file_exists($resolver_path) && function_exists('et_get_option') ) { | |
require_once $resolver_path; | |
} | |
if ( ! class_exists('Smartcrawl_Endpoint_Resolver') || ! function_exists('et_get_option') ) return; | |
$this->set_title(); | |
$this->set_description(); | |
add_filter( 'wds_title', array( $this, 'extra_homepage_title' ), 10, 1 ); | |
add_filter( 'wds_metadesc', array( $this, 'extra_homepage_description' ), 10, 1 ); | |
} | |
public function set_title() { | |
global $shortname; | |
$is_custom_title = et_get_option( $shortname . '_seo_home_title' ); | |
if ( $is_custom_title != 'false' ) { | |
$this->title = et_get_option( $shortname . '_seo_home_titletext' ); | |
} | |
if ( $is_custom_title == 'false' || empty($this->title) ) { | |
$this->title = get_bloginfo('name'); | |
} | |
} | |
public function set_description() { | |
global $shortname; | |
$this->description = et_get_option( $shortname . '_seo_home_descriptiontext' ); | |
if ( empty($this->description) ) { | |
$this->description = get_bloginfo('description'); | |
} | |
} | |
public function get_or_check_location( $location = null ) { | |
if ( empty($location) ) return Smartcrawl_Endpoint_Resolver::resolve()->get_location(); | |
return Smartcrawl_Endpoint_Resolver::resolve()->get_location() == $location; | |
} | |
public function extra_homepage_title( $title ) { | |
if ( ! $this->get_or_check_location('static_home') ) return $title; | |
return $this->title; | |
} | |
public function extra_homepage_description( $description ) { | |
if ( ! $this->get_or_check_location('static_home') ) return $description; | |
return $this->description; | |
} | |
} | |
function Render_SmartCrawl_title_description_fix_for_Extra_theme() { | |
$GLOBALS['SmartCrawlTitleDescriptionFixForExtraTheme'] = SmartCrawlTitleDescriptionFixForExtraTheme::get_instance(); | |
} | |
} | |
add_action( 'init', 'Render_SmartCrawl_title_description_fix_for_Extra_theme' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment