WordPress.org

Ready to get started?Download WordPress

Forums

Jquery (15 posts)

  1. germz
    Member
    Posted 5 years ago #

    I am trying to create a php conditional tag that will make my jquery load ONLY on other pages other than my homepage.

    http://codex.wordpress.org/Conditional_Tags

    This is my website,

    http://www.thegermz.com

    Also, I am not calling for the jquery to load as the jquery is loading on it's own... I'm not sure if it's the wp_head that's calling it, but if it is the wp head I can't disable it from the homepage as I have some plugins there.

  2. stvwlf
    Member
    Posted 5 years ago #

    The easiest way to load the jQuery library is to put this
    <?php wp_enqueue_script('jquery'); ?> in header.php
    BEFORE <?php wp_head(); ?>

    To load your jquery routines on all pages except the homepage

    <?php if ( !is_home() ) { ?>
        ====  jquery code here =====
    <?php } ?>

    That assumes your homepage is your blog posts page. If you use a static top page, use !is_front_page() iintead of !is_home()

  3. zeniph
    Member
    Posted 5 years ago #

    Many pluggins that have a dependency on jquery (or other js library etc) will package it up with the pluggin and write it into every page via wp_head().

    you could:

    • edit the pluggin placing the conditional code within it
    • or create a homepage template exluding wp_head() and manually insert all of your header resources (copy and paste the paths from an existing page with wp_head())
  4. germz
    Member
    Posted 5 years ago #

    stvwlf, I tried the code but it didn't work :(. I placed it before my wp_head.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title><?php bloginfo('name'); ?> <?php if ( is_single() ) { ?> &raquo; Blog Archive <?php } ?> <?php wp_title(); ?></title>
    
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" />
    <link rel="Shortcut Icon" href="<?php echo get_settings('home'); ?>/wp-content/themes/church_10/images/favicon.ico" type="image/x-icon" />
    <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo('rss2_url'); ?>" />
    <link rel="alternate" type="text/xml" title="RSS .92" href="<?php bloginfo('rss_url'); ?>" />
    <link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="<?php bloginfo('atom_url'); ?>" />
    <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
    <?php wp_get_archives('type=monthly&format=link'); ?>
    <?php if ( !is_home() ) { ?>
        <?php wp_enqueue_script('jquery'); ?>
    <?php } ?>
    <?php wp_head(); ?>
    
    </head>
    <body>
    
    <div id="page">
    <div id="header">
    <div class="Ad">
    
    <?php if(function_exists('oiopub_banner_zone')) oiopub_banner_zone(2, 'center'); ?>
    
    </div>
    
    <!--
    <div id="headerimg">
    
    			<h1><a href="<?php echo get_option('home'); ?>/"><?php bloginfo('name'); ?></a></h1>
    			<div class="description"><?php bloginfo('description'); ?></div>
    		</div>
    -->
    
    		<ul id="nav">
    			<?php wp_list_pages('sort_column=menu_order&depth=1&title_li=');?>
    		</ul>
    	</div>
    
    <?php include (TEMPLATEPATH . '/searchform.php'); ?>
    
    	<!--/header -->

    And zeniph, even when I don't have wp_head the jquery still loads, i know because it appears on even a fresh installation of wordpress.

  5. germz
    Member
    Posted 5 years ago #

    Actually never mind I just took out the wp head and the jquery dissappeared so it definitely is in the jquery. But I don't know what's causing it to load.

    There are my plugins at the moment.

    Akismet 2.2.3

    Akismet checks your comments against the Akismet web service to see if they look like spam or not. You need a WordPress.com API key to use it. You can review the spam it catches under “Comments.” To show off your Akismet stats just put <?php akismet_counter(); ?> in your template. See also: WP Stats plugin. By Matt Mullenweg.
    Deactivate | Edit
    All in One SEO Pack 1.4.7

    Out-of-the-box SEO for your WordPress blog. By Michael Torbert.
    Deactivate | Edit
    cforms II 7.52

    cforms II offers unparalleled flexibility in deploying contact forms across your blog. Features include: comprehensive SPAM protection, Ajax support, Backup & Restore, Multi-Recipients, Role Manager support, Database tracking and many more. Please see the VERSION HISTORY for what’s new and current bugfixes. By Oliver Seidel.
    Deactivate | Edit
    commentluv 2.6.5

    Plugin to show a link to the last post from the commenters blog in their comment. Just activate and it’s ready. Will parse a feed from most sites that have a feed location specified in its head html. See the Settings Page for styling and text output options. By Andy Bailey.
    Deactivate | Edit | Settings
    Executable PHP widget 1.1

    Like the Text widget, but it will take PHP code as well. Heavily derived from the Text widget code in WordPress. By Otto.
    Deactivate | Edit
    Featured Content Gallery 3.1.0

    Used to create a customizable rotating image gallery anywhere within your WordPress site. FeaturedContentGallery.com: plugin page, instructions, gallery and support. By iePlexus.
    Deactivate | Edit
    FeedBurner FeedSmith 2.3.1

    Originally authored by Steve Smith, this plugin detects all ways to access your original WordPress feeds and redirects them to your FeedBurner feed so you can track every possible subscriber. By FeedBurner.
    Deactivate | Edit
    FireStats 1.5.12-stable

    Statistics plugin for WordPress. By Omry Yadan.
    Deactivate | Edit
    Version 1.6.0-stable is available! click here for more info
    Google XML Sitemaps 3.1.2

    This plugin will generate a sitemaps.org compatible sitemap of your WordPress blog which is supported by Ask.com, Google, MSN Search and YAHOO. Configuration Page By Arne Brachhold.
    Deactivate | Edit
    Gravatar 1.1

    This plugin allows you to generate a gravatar URL complete with rating, size, default, and border options. See the documentation for syntax and usage. By Tom Werner.
    Deactivate | Edit
    OIOpublisher Direct 2.0 2.08

    Control your Ad Space with OIOpublisher. By Simon Emery.
    Deactivate | Edit
    Recent Comments Widget 4.0

    This plugin will add a list of the most frequent comments posted to your blog. They are gathered in descending order (newest at the top), but then group them together by post title, so that comments from the same post are listed together. The list items will be links to the comments, and will contain the name of the commenter. Derived from the “Top/Recent Commenters” plugin by Scott Reilly (http://www.coffee2code.com/wp-plugins/) By Jared Bangs.
    Deactivate | Edit
    ShareThis 2.3

    Let your visitors share a post/page with others. Supports e-mail and posting to social bookmarking sites. Configuration options are here. Questions on configuration, etc.? Make sure to read the README. By ShareThis and Crowd Favorite (crowdfavorite.com).
    Deactivate | Edit
    Subscribe To Comments 2.1.2

    Allows readers to receive notifications of new comments that are posted to an entry. Based on version 1 from Scriptygoddess By Mark Jaquith.
    Deactivate | Edit
    Woopra 1.4.0.3

    This plugin adds Woopra’s real-time analytics to any WordPress installation. Simply sign up at Woopra.com, then activate the plugin and configure your site ID in the Woopra settings. By Elie El Khoury.
    Deactivate | Edit
    WordPress.com Stats 1.3.7

    Tracks views, post/page views, referrers, and clicks. Requires a WordPress.com API key. By Andy Skelton.
    Deactivate | Edit
    WP-Polls 2.40

    Adds an AJAX poll system to your WordPress blog. You can easily include a poll into your WordPress’s blog post/page. WP-Polls is extremely customizable via templates and css styles and there are tons of options for you to choose to ensure that WP-Polls runs the way you wanted. It now supports multiple selection of answers. By Lester 'GaMerZ' Chan.
    Deactivate | Edit
    WP-PostRatings 1.40

    Adds an AJAX rating system for your WordPress blog’s post/page. By Lester 'GaMerZ' Chan.
    Deactivate | Edit
    WP Grins

  6. s_ha_dum
    Member
    Posted 5 years ago #

    Everywhere you see 'AJAX' in those descriptions you are loading javascript and there is a good chance it is jQuery. And several of them seem to have good reason to load on every page-- the ratings plugin for example.

    You could also grep you plugin directory wp_head and narrow the search some-- maybe.

  7. germz
    Member
    Posted 5 years ago #

    Thank you.
    Is there any way to make wp_head not load in the homepage but run on all the rest of the pages?

  8. s_ha_dum
    Member
    Posted 5 years ago #

    You could build a home page template that doesn't call wp_head(). You'll loose some functionality and I'm not sure its worth it. What is it you are trying to accomplish by not loading jQuery on one page?

  9. chaoskaizer
    Member
    Posted 5 years ago #

    you could try unregister jquery on frontpage (this will also break any plugin's that depend on jQuery) then reregister it back and load it where u want it.

  10. germz
    Member
    Posted 5 years ago #

    How would I go on doing that?

  11. zeniph
    Member
    Posted 5 years ago #

    Is there any way to make wp_head not load in the homepage but run on all the rest of the pages?

    yes - slight variation on what stvwlf originally posted

    <?php if ( !is_home() ) {
        wp_head();
    } ?>

    is_front_page() may also be used depending on your blog setup

  12. germz
    Member
    Posted 5 years ago #

    I will try that thank you very much I really appreciate it.
    Do you know how to block or as kaizer said, unregister a jquery call made from wp_head and then register back if jquery loads anywhere else other than the front page?

  13. zeniph
    Member
    Posted 5 years ago #

    not entirely sure at what chaoskaizer was alludinng to - perhaps jQuery.noConflict()

    regardless to isolate what ever you want to the home page only you will need to add conditional code

    perhaps let us know the core issue your trying to solve here i.e. why dont you want jquery on the homepage

  14. chaoskaizer
    Member
    Posted 5 years ago #

    How would I go on doing that?

    add inside your theme's functions.php

    <?php
    wp_enqueue_script('jquery');
    add_action('wp_head','script_controller',9);
    function script_controller(){
    	global $wp_query;
    	$handle = 'jquery';
    
    	if ($wp_query->is_home || $wp_query->is_front_page){
    		// brute uninstall
    		wp_deregister_script($handle);
    	} else {
    		wp_register_script($handle,'/wp-includes/js/jquery/jquery.js', false, '1.2.6');
    	}
    	wp_enqueue_script($handle);
    }
    ?>
  15. germz
    Member
    Posted 5 years ago #

    Thank you VERY much guys I really appreciate it, I managed to fix the problem. Thanks so much!

Topic Closed

This topic has been closed to new replies.

About this Topic