This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Child Theme / Javascript Issue

  • Creator
    Topic
  • #3129
    dalhic
    Participant

    Dear Support,

    We are using your theme “Barely Corporate” and have a child theme set up. The website we are creating requires accessibility options. We have tried to add javascript into the header.php of the child theme, which sounds like a very simple thing to do, but its not executing. Can you help try and solve the reason why the JS is not executing. We have triple checked that all paths, files are correct – it should be working. But we can’t figure out why.

    Any ideas, please let us know.

    Also, is there any way we can implement a secondary navigation into the header, or set up a separate widget area into the header area?

    Many thanks for any replies,

    Tom

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #3153
    Jason Bobich
    Keymaster

    We have tried to add javascript into the header.php of the child theme, which sounds like a very simple thing to do, but its not executing.

    You shouldn’t be putting any javascript in your header.php. Here’s how to incorporate javascript files in WordPress (which you should be doing from your Child theme’s functions.php) — http://codex.wordpress.org/Function_Reference/wp_enqueue_script

    Example:

    function my_scripts_method() {
        wp_enqueue_script( 'my_script', get_stylesheet_directory_uri() . '/my-file.js' );            
    }    
    add_action('wp_enqueue_scripts', 'my_scripts_method');

    As far as debugging your specific javascript, I’m not quite sure there’s really much I can do there for you. Do you have a link to what you’re doing?

    Also, is there any way we can implement a secondary navigation into the header, or set up a separate widget area into the header area?

    You’ll want to familiarize yourself with an action hook is in WordPress. And then, you’ll be able to easily tap into many areas of the theme from your functions.php of your Child theme.

    http://dev.themeblvd.com/tutorial/actions/

    http://dev.themeblvd.com/tutorial/primary-framework-action-hooks/

    This might help from another support topic:

    =============

    How do I add a widget area to the right side of the header?

    If you’re wanting to make PHP customizations, you are going to have to learn the basics of PHP — how to create a function, what variables are, what arrays are, etc — and how a WordPress functions.php file works. There’s just no way around this. All of your PHP customizations — your new widget area, your action hook modifications, everything — are going to be placed within the functions.php of your Child theme below where the themeblvd.php framework file is included.

    So, in general, it’s a good idea to start familiarizing yourself with the hook system itself and what a WordPress action hook is in general. So, your first question is basically “How do I put something in the right side of the header?”

    And the answer would be to hook your custom content to “themeblvd_header_addon” and then position it with CSS. You can quickly see that by checking out the actions map:

    http://dev.themeblvd.com/tutorial/primary-framework-action-hooks/

    With Swagger specifically, you’re going to have to unhook what’s already there. So an example of just outputting some text would be to do something like this:

    /**
     * My header content
     */
    function my_header_content() {
    	echo 'This content will show in the header.';
    }
    remove_all_actions( 'themeblvd_header_addon' );
    add_action( 'themeblvd_header_addon', 'my_header_content' );

    The next question is essentially, “How do I create and display a widget area?” If you’re just trying to do this in WordPress in general, it’s very easy. Register it from your Child theme’s functions.php and display it within whatever function you’re hooking into the header.

    Now if you want to get fancy and use some of the framework’s unique things, you can register a “sidebar location.” This is what you were reading about in that tutorial. Basically this means that now if you wanted you could use the tools at Appearance > Widget Areas to then create custom widget areas that could then be swapped into that header location depending on different pages and what not.

    The full breakdown on that is here:

    http://dev.themeblvd.com/tutorial/widget-areas-for-the-end-user/#widget-area-locations

    http://dev.themeblvd.com/tutorial/default-widget-area-locations/

    http://dev.themeblvd.com/tutorial/addremove-widget-area-location/

    Expanding on the example I gave above to go with the code you were originally asking about, it would go something like this:

    /**
     * Add new sidebar location.
     */
    themeblvd_add_sidebar_location( 'my_header_widget_area', 'My Header Widget Area', 'collapsible' );
    
    /**
     * My header content
     */
    function my_header_content() {
    	themeblvd_display_sidebar( 'my_header_widget_area' );
    }
    remove_all_actions( 'themeblvd_header_addon' );
    add_action( 'themeblvd_header_addon', 'my_header_content' );
Viewing 1 replies (of 1 total)
  • The forum ‘Barely Corporate Responsive WordPress Theme’ is closed to new topics and replies.