ThemeShaper Forums » Thematic

[closed]

Replace superfish script by a customscript

(10 posts)
  • Started 2 years ago by guivag
  • Latest reply from guivag
  • This topic is resolved

Tags:

  1. guivag
    Member

    Hi !

    I wanted to add some custom script into the <head> of my page.
    So i search where the superfish script is called and found it define by a php function into the header-extensions.php.

    I didnt care about the superfish script so i say to myself: "i just have to replace it by my script at the same place and it should work..."

    I removed all the superfish loading part of the code (located after: "// Load scripts for the jquery Superfish plugin http://users.tpg.com.au/j_birch/plugins/superfish/#examples") and paste this instead:

    function thematic_head_scripts() {
    $scriptdir_start = "\t";
    $scriptdir_start .= '<script type="text/javascript" src="';
    $scriptdir_start .= get_bloginfo('template_directory');
    $scriptdir_start .= '/library/scripts/';

    $scriptdir_end = '"></script>';

    //$scripts = "\n";
    $scripts .= $scriptdir_start . 'my_script_01.js' . $scriptdir_end . "\n";

    // Print scripts
    print $scripts;
    }

    But my script dont seems to be loaded...
    What did i do wrong ?

    Thanks for your supplies...

    Posted 2 years ago #
  2. That is the wrong way to do it. You want to use something like this, using the wp_enque_script method (using fitvids as an example):

    function childtheme_script_manager() {
    
        wp_register_script('fitvids-js', get_stylesheet_directory_uri() . '/js/jquery.fitvids.js', array('jquery'), false, true);
    
        // enqueue the scripts for use in theme
        wp_enqueue_script ('fitvids-js');
    }
    add_action('wp_enqueue_scripts', 'childtheme_script_manager');

    reference: http://codex.wordpress.org/Function_Reference/wp_enqueue_script

    Posted 2 years ago #
  3. to remove all the superfish scripts you can do any of the following:

    function childtheme_override_head_scripts(){
      //sound of one hand clapping
    }

    or

    function kia_filter_scripts(){
      //sound of one hand clapping (or return FALSE; would also work)
    }
    add_filter('thematic_header_scripts','kia_filter_scripts');

    or

    function kia_remove_scripts(){
      remove_action('wp_head','thematic_header_scripts');
    }
    add_action('init','kia_remove_scripts');

    or perhaps the most elegant:

    add_filter('thematic_use_superfish','__return_false');

    thematic 1.0 (which officially IS in the review queue right this moment) will properly enqueue scripts in the style suggested by jagst3r15.

    nb: no need to register and then enqueue in his example:

    function childtheme_script_manager() {
    
        wp_enqueue_script('fitvids-js', get_stylesheet_directory_uri() . '/js/jquery.fitvids.js', array('jquery'), false, true);
    
    }
    add_action('wp_enqueue_scripts', 'childtheme_script_manager');

    will work just fine.

    Posted 2 years ago #
  4. guivag
    Member

    Sorry but i'm a pure noob in php/wordpress scripting so:

    where do i add the:

    add_filter('thematic_use_superfish','__return_false');

    ?

    where di i add the:

    function childtheme_script_manager() {

    wp_enqueue_script('fitvids-js', get_stylesheet_directory_uri() . '/js/jquery.fitvids.js', array('jquery'), false, true);

    }
    add_action('wp_enqueue_scripts', 'childtheme_script_manager');

    And in the case of a thematic framework do i replace all the:"childtheme_script_manager()" by "thematic_script_manager()" ?

    So if my new script is located in /library/scripts/slider_01.js my function look like this?

    function thematic_script_manager() {

    wp_enqueue_script('silder_01', get_stylesheet_directory_uri() . '/library/scripts/slider_01.js', array('jquery'), false, true);

    }
    add_action('wp_enqueue_scripts', 'thematic_script_manager');

    Sorry if i ask too much question when awnser are all in the codex but i'm still doing the layout of my web page for now. So i'm ok with CSS, i'm ok with Jquery luanguage, but i didnt try for now to call any database and learn php. And the thematic php architecture is still a little blurry for me...
    I just need a little help to finish my layout before i get to the php learning.

    Posted 2 years ago #
  5. guivag
    Member

    Ok, it seems that i can declare the thematic_script_manager() function anywhere in the header-extension.php or function.php. (cause my function.php call header-extension.php...)

    So i must be wrong with the script path or with the function name.

    But i test the two names: thematic_script_manager() and childtheme_script_manager().
    And i test different path... even this one: "http://mywebsite.com/wp-content/themes/otomatic/library/scripts/slider_01.js" who must be correct.
    And i never see my script appears in firebug... :s

    Posted 2 years ago #
  6. guivag
    Member

    With some more search on the forum i finally figure out wht's wrong.

    function childtheme_script_manager() {

    wp_enqueue_script('silder_01.js', get_stylesheet_directory_uri() . '/library/scripts/slider_01.js', array('jquery'), false, true);

    }
    add_action('wp_enqueue_scripts', 'childtheme_script_manager');

    With the ".js" in the name of the script and with a path comming from my childtheme directory the script seems to be loaded (even if he dont seems to work^^ He is detected as v3.3.2 script when jquery is at 1.7.1...) But thats a first step...

    Thank you ; )

    edit:
    When i look to my html code the version dont seems to be the only problem. The sript is loaded but just after the wpadminbar script in the bottom of my <body> when it should appears into my <head>.

    Posted 2 years ago #
  7. guivag
    Member

    Well.. I remove the "false, true" part at the end of the code and now the script is correctly loaded into my <head>.

    Script dont work but i suppose that's cause i wanted to modify a css parameter and this parameter is located into a default.css call by the style.css. The script must don't find it... (or it's this "?ver=3.3.2" problem.) I will search further on those directions.

    Posted 2 years ago #
  8. have you done any reading on how to create a proper child theme? all functions go in your child theme's functions.php

    there's a sample child theme that comes in the thematic folder. you can copy the folder directly into wp-content/themes, activate it and start from that.

    please don't edit header-extensions.php

    if you are confused wp_enqueue_script then please read the codex page
    http://codex.wordpress.org/Function_Reference/wp_enqueue_script

    that final "true" means you wish to load it in the footer, which is a good place for many scripts.... it can help pages load faster to put scripts in the footer.

    Posted 2 years ago #
  9. guivag
    Member

    Yeah i read many topic about childtheme creation but simply copy the arborecense of the parent into the child to edit it. At the moment it seems to be the faster way but now, i admit it, it complicate everything.^^

    Tomorrow i will start a new child theme from the begining to keep a clean arborecense with only the things i've created.

    Anyways thanks helga, you post many helpfull things on this forum :]

    Posted 2 years ago #
  10. guivag
    Member

    I finally get it work using this code:

    // IT WORKS !

    function re_init_jQuery() {
    if (!is_admin()) {
    wp_deregister_script('jquery');
    wp_register_script('jquery','http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js', false, '1.7.1');
    wp_enqueue_script('jquery');
    }
    }
    add_action('init', 're_init_jQuery');

    function childtheme_script_manager() {
    wp_enqueue_script('silder_01.js', get_bloginfo('stylesheet_directory') . '/script/slider_01.js', array('jquery'), '1.7.1', false);
    }

    add_action('wp_enqueue_scripts', 'childtheme_script_manager');

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.