Created
March 14, 2014 14:40
-
-
Save ximosa/9549004 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 | |
require('xa-register.class.php'); | |
// En el frontend | |
// CSS | |
add_style('mi_estilo','css/estilo.css'); | |
// JS | |
add_script('mi_script','js/script.js'); | |
//En el backend | |
//CSS | |
add_style('admin_estilo','admin/css/style.css','backend'); | |
//JS | |
add_script('admin_style','admin/js/script.js','backend'); | |
?> |
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 | |
/* | |
| Autor: Xavi Martínez | |
| Web : http://www.xavim.com | |
| | |
| | |
| | |
| XA_REGISTER (Registra hojas de estilo y scripts en wordpress) | |
|------------------------------------------------------------------------------- | |
| Clase para registrar hojas de estilo y scripts en wordpress, pudiendo elegir | |
| si queremos subir el script y/o la hoja de estilos en el frontend o backend | |
| | |
| $handle = Es el nombre del script/estilo | |
| $src = La url del archivo. | |
| $where = Define donde se mostrará, si en el frontend o backend. | |
| (default = frontend). | |
| | |
| | |
| Ejemplos : | |
| | |
| * FRONTEND * | |
| | |
| add_script('bootstrap_js','assets/bootstrap/js/bootstrap.js'); | |
| add_style('bootstrap_css','assets/bootstrap/css/bootstrap.css'); | |
| | |
| * BACKEND * | |
| | |
| add_style('admin_style','css/admin-style.css','backend'); | |
| add_script('admin_script','js/admin-script.js','backend'); | |
| | |
*/ | |
class xa_register { | |
public function style($handle,$src,$where) { | |
if(is_admin()): | |
if($where == 'backend'): | |
$this->cargar_archivo($handle,$src,'css'); | |
else: endif; | |
else: | |
if($where == 'frontend'): | |
$this->cargar_archivo($handle,$src,'css'); | |
else: endif; | |
endif; | |
} | |
public function script($handle,$src,$where) { | |
if(is_admin()): | |
if($where == 'backend'): | |
$this->cargar_archivo($handle,$src,'js'); | |
else: endif; | |
else: | |
if($where == 'frontend'): | |
$this->cargar_archivo($handle,$src,'js'); | |
else: endif; | |
endif; | |
} | |
private function cargar_archivo($handle,$src,$type) { | |
if($type == 'js') : | |
wp_enqueue_script($handle, get_stylesheet_directory_uri().'/'.$src, array( 'jquery') ); | |
elseif($type == 'css') : | |
wp_register_style($handle, get_stylesheet_directory_uri().'/'.$src); | |
wp_enqueue_style($handle); | |
endif; | |
} | |
} | |
$xa_register = new xa_register(); | |
function add_style($handle,$src,$where='frontend') { | |
global $xa_register; | |
$xa_register->style($handle,$src,$where); | |
} | |
function add_script($handle,$src,$where='frontend') { | |
global $xa_register; | |
$xa_register->script($handle,$src,$where); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment