2011-07-20 142 views
0

我想重新声明一个函数在一个已经被父主题使用的WordPress主题中。但是,尝试这样做时出现“致命错误:无法重新声明”消息。WordPress的儿童主题

另外,我尝试使用没有运气以下:

if (!function_exists('jr_load_scripts')) { 
    // do fancy things here... 
} 

这里的the link,如果你想有一个快速浏览一下......

编辑:下面是完整的代码:

if (!function_exists('jr_load_scripts')) { 
function jr_load_scripts() { 
global $app_abbr; 

$http = (is_ssl()) ? 'https' : 'http'; 

// load google cdn hosted scripts if enabled 
if (get_option($app_abbr.'_google_jquery') == 'yes') : 

    wp_deregister_script('jquery'); 
    wp_register_script('jquery', (''.$http.'://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'), false, '1.4.2'); 
    wp_register_script('jquery-ui-custom', ''.$http.'://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js', false, '1.8'); 

else : 

    wp_register_script('jquery-ui-custom', get_bloginfo('template_directory').'/includes/js/jquery-ui-1.8.custom.min.js', false, '1.8'); 

endif; 

wp_enqueue_script('jquery'); 
wp_enqueue_script('jquery-ui-custom'); 

wp_enqueue_script('jquery-tag', get_bloginfo('template_directory').'/includes/js/jquery.tag.js', array('jquery'), ''); 
wp_enqueue_script('smoothscroll', get_bloginfo('template_directory').'/includes/js/smoothscroll.js', array('jquery'), ''); 
wp_enqueue_script('lazyload', get_bloginfo('template_directory').'/includes/js/jquery.lazyload.mini.js', array('jquery'), '1.5.0'); 
wp_enqueue_script('elastic', get_bloginfo('template_directory').'/includes/js/jquery.elastic.js', array('jquery'), '1.0'); 
wp_enqueue_script('fancybox', get_bloginfo('template_directory').'/includes/js/jquery.fancybox-1.3.4.pack.js', array('jquery'), '1.3.4'); 
wp_enqueue_script('qtip', get_bloginfo('template_directory').'/includes/js/jquery.qtip.min.js', array('jquery'), '1.0.0-rc3'); 
wp_enqueue_script('general', get_bloginfo('template_directory').'/includes/js/theme-scripts.js', array('jquery'), '3.0'); 

$jr_enable_indeed_feeds = get_option('jr_enable_indeed_feeds'); 
if ($jr_enable_indeed_feeds=='yes') : 

    wp_enqueue_script('indeed-api', ''.$http.'://www.indeed.com/ads/apiresults.js'); 

wp_enqueue_script('jqtransform', get_bloginfo('template_directory') . '/includes/jqtransformplugin/jquery.jqtransform.js', array('jquery'),''); 

endif; 
} 

EDIT2:根据要求 - 主题 - enque的内容ue文件:

<?php 
/** 
* These are scripts used within the JobRoller theme 
* To increase speed and performance, we only want to 
* load them when needed 
* 
* @package JobRoller 
* @version 1.0 
* 
*/ 

function jr_load_scripts() { 
    global $app_abbr; 

    $http = (is_ssl()) ? 'https' : 'http'; 

    // load google cdn hosted scripts if enabled 
    if (get_option($app_abbr.'_google_jquery') == 'yes') : 

     wp_deregister_script('jquery'); 
     wp_register_script('jquery', (''.$http.'://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'), false, '1.4.2'); 
     wp_register_script('jquery-ui-custom', ''.$http.'://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js', false, '1.8'); 

    else : 

     wp_register_script('jquery-ui-custom', get_bloginfo('template_directory').'/includes/js/jquery-ui-1.8.custom.min.js', false, '1.8'); 

    endif; 

    wp_enqueue_script('jquery'); 
    wp_enqueue_script('jquery-ui-custom'); 

    wp_enqueue_script('jquery-tag', get_bloginfo('template_directory').'/includes/js/jquery.tag.js', array('jquery'), ''); 
    wp_enqueue_script('smoothscroll', get_bloginfo('template_directory').'/includes/js/smoothscroll.js', array('jquery'), ''); 
    wp_enqueue_script('lazyload', get_bloginfo('template_directory').'/includes/js/jquery.lazyload.mini.js', array('jquery'), '1.5.0'); 
    wp_enqueue_script('elastic', get_bloginfo('template_directory').'/includes/js/jquery.elastic.js', array('jquery'), '1.0'); 
    wp_enqueue_script('fancybox', get_bloginfo('template_directory').'/includes/js/jquery.fancybox-1.3.4.pack.js', array('jquery'), '1.3.4'); 
    wp_enqueue_script('qtip', get_bloginfo('template_directory').'/includes/js/jquery.qtip.min.js', array('jquery'), '1.0.0-rc3'); 
    wp_enqueue_script('general', get_bloginfo('template_directory').'/includes/js/theme-scripts.js', array('jquery'), '3.0'); 

    $jr_enable_indeed_feeds = get_option('jr_enable_indeed_feeds'); 
    if ($jr_enable_indeed_feeds=='yes') : 

     wp_enqueue_script('indeed-api', ''.$http.'://www.indeed.com/ads/apiresults.js'); 

    endif; 
} 

// this function is called when submitting a new job listing 
function jr_load_form_scripts() { 
    // only load the tinymce editor when html is allowed 
    if (get_option('jr_html_allowed') == 'yes') { 
     wp_enqueue_script('tiny_mce', get_bloginfo('url').'/wp-includes/js/tinymce/tiny_mce.js'); 
     wp_enqueue_script('tiny_mce-wp-langs-en', get_bloginfo('url').'/wp-includes/js/tinymce/langs/wp-langs-en.js'); 
    } 
} 

// to speed things up, don't load these scripts in the WP back-end (which is the default) 
if(!is_admin()) { 
    add_action('wp_print_scripts', 'jr_load_scripts'); 
    // add_action('wp_print_styles', 'cp_load_styles'); 
} 
+0

这可能是在[WordPress的stackexchange网站]更好(http://wordpress.stackexchange.com) –

+0

请张贴的'jobroller /包括/主题enqueue.php' – Dogbert

回答

0

您不能覆盖该函数,因为父主题的声明是在声明后执行的,并且它不会检查函数是否已经存在。

唯一的方法是将父主题的函数声明包装在if条件中。

if (!function_exists('jr_load_scripts')) { 

} 
+0

坚果内容。非常感谢你! –