1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need Help with Wordpress HTML Code

Discussion in 'HTML & Website Design' started by akl26, Sep 7, 2011.

  1. #1
    Help! Tried to add the Google Analytics code to the function.php section of my WordPress theme (AgentPress, made for real estate sites), and now can't get out of an error message, showing both in WordPress and on the site itself.

    The error showing is: Parse error: syntax error, unexpected '<' in /home/densen5/signatureassociates.net/wp-content/themes/agentpress/functions.php on line 114

    But cannot find that line of code?

    The HTML for this section follows, the new Google code was added second to the bottom... What am I missing? Thank you!


    <?php
    // Start the engine
    require_once(TEMPLATEPATH.'/lib/init.php');
    require_once(STYLESHEETPATH.'/lib/init.php');

    // Add new image sizes
    add_image_size('Slider', 920, 300, TRUE);
    add_image_size('Featured Properties', 290, 200, TRUE);
    add_image_size('Featured Posts', 115, 115, TRUE);
    add_image_size('Small Thumbnail', 110, 80, TRUE);

    // Load script for jFlow slider
    add_action('get_header', 'agentpress_load_scripts');
    function agentpress_load_scripts() {
    wp_enqueue_script('jflow', CHILD_URL.'/lib/js/jquery.flow.1.1.js', array('jquery'), '1.1', TRUE);
    }

    // Load parameters for jFlow slider
    add_action('wp_footer', 'agentpress_jflow_params');
    function agentpress_jflow_params() {
    $timer = intval(genesis_get_option('slider_timer'));
    $duration = intval(genesis_get_option('slider_duration'));
    $output = '
    jQuery(document).ready(function($) {
    $("div#controller").jFlow({
    slides: "#slides",
    width: "920px",
    height: "300px",
    timer: '.$timer.',
    duration: '.$duration.'
    });
    });
    ';
    $output = str_replace(array("\n","\t","\r"), '', $output);
    echo '<script type=\'text/javascript\'>'.$output.'</script>';
    }

    // Add the slider on the homepage above the content area
    add_action('genesis_after_header', 'agentpress_include_slider');
    function agentpress_include_slider() {
    if(is_front_page() && genesis_get_option('slider_enable'))
    require(CHILD_DIR . '/slider.php');
    }

    // Force layout on homepage
    add_filter('genesis_pre_get_option_site_layout', 'agentpress_home_layout');
    function agentpress_home_layout($opt) {
    if ( is_home() )
    $opt = 'content-sidebar';
    return $opt;
    }

    // Add a read more link to the excerpt
    add_filter('excerpt_more', 'agentpress_excerpt_more');
    function agentpress_excerpt_more($more) {
    return '... <a href="'.get_permalink().'" rel="nofollow">Read More</a>';
    }

    // Remove post-info, post-meta, and author box from property posts
    add_action( 'get_header', 'agentpress_remove_property_extras' );
    function agentpress_remove_property_extras() {
    if( is_single() && genesis_get_custom_field('_features_1_col1_1') ) {
    remove_action('genesis_before_post_content', 'genesis_post_info');
    remove_action('genesis_after_post_content', 'genesis_post_meta');
    remove_action('genesis_after_post', 'genesis_do_author_box');
    add_filter( 'genesis_options', 'agentpress_remove_property_comments', 10, 2 );
    }
    }

    // Remove comments from property posts
    function agentpress_remove_property_comments($options, $setting) {
    if($setting == GENESIS_SETTINGS_FIELD) {
    $options['comments_posts'] = 0;
    }
    return $options;
    }

    // Add new box to the Genesis -> Theme Settings page
    add_action('admin_menu', 'agentpress_add_settings_boxes', 11);
    function agentpress_add_settings_boxes() {
    global $_genesis_theme_settings_pagehook;
    add_meta_box('genesis-theme-settings-slider', __('Slider Settings', 'agentpress'), 'agentpress_theme_settings_slider_box', $_genesis_theme_settings_pagehook, 'column2');
    }
    function agentpress_theme_settings_slider_box() { ?>
    <p><input type="checkbox" name="<?php echo GENESIS_SETTINGS_FIELD; ?>[slider_enable]" id="<?php echo GENESIS_SETTINGS_FIELD; ?>[slider_enable]" value="1" <?php checked(1, genesis_get_option('slider_enable')); ?> /> <label for="<?php echo GENESIS_SETTINGS_FIELD; ?>[slider_enable]"><?php _e('Enable the Slider?', 'agentpress'); ?></label></p>
    <p><label><?php _e('Category', 'agentpress'); ?>: <?php wp_dropdown_categories(array('name' => GENESIS_SETTINGS_FIELD.'[slider_cat]', 'selected' => genesis_get_option('slider_cat'), 'orderby' => 'Name' , 'hierarchical' => 1, 'show_option_all' => __("All Categories", 'agentpress'), 'hide_empty' => '0')); ?></label></p>
    <p><label><?php _e('Number of Posts', 'agentpress'); ?>: <input type="text" name="<?php echo GENESIS_SETTINGS_FIELD; ?>[slider_num]" value="<?php genesis_option('slider_num'); ?>" size="5" /></label></p>
    <p><label><?php _e('Time Between Slides (in milliseconds)', 'agentpress'); ?>: <input type="text" name="<?php echo GENESIS_SETTINGS_FIELD; ?>[slider_timer]" value="<?php genesis_option('slider_timer'); ?>" size="5" /></label></p>
    <p><label><?php _e('Slide Transition Speed (in milliseconds)', 'agentpress'); ?>: <input type="text" name="<?php echo GENESIS_SETTINGS_FIELD; ?>[slider_duration]" value="<?php genesis_option('slider_duration'); ?>" size="5" /></label></p>
    <?php
    }

    // Add new default values for the slider
    add_filter('genesis_theme_settings_defaults', 'agentpress_slider_defaults');
    function agentpress_slider_defaults($defaults) {
    $defaults['slider_enable'] = 1;
    $defaults['slider_num'] = 1;
    $defaults['slider_timer'] = 6000;
    $defaults['slider_duration'] = 400;
    return $defaults;
    }

    // Register Sidebars
    genesis_register_sidebar(array(
    'name'=>'Featured Properties',
    'description' => 'This is the featured properties section of the homepage.',
    'before_title'=>'<h4 class="widgettitle">','after_title'=>'</h4>'
    ));
    genesis_register_sidebar(array(
    'name'=>'Featured Posts',
    'description' => 'This is the featured posts section of the homepage.',
    'before_title'=>'<h4 class="widgettitle">','after_title'=>'</h4>'
    ));
    <script type="text/javascript">

    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-25587143-1']);
    _gaq.push(['_trackPageview']);

    (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
    </script>
    ));
    genesis_register_sidebar(array(
    'name'=>'Multi-Agent Page',
    'description' => 'This is the main content area of the mult-agent page template.',
    'before_title'=>'<h4 class="widgettitle">','after_title'=>'</h4>'
    ));
    ?
     
    akl26, Sep 7, 2011 IP
  2. developerpanda

    developerpanda Peon

    Messages:
    104
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I am not entirely sure whether functions.php is the right place to add the Google Analytics code but anyways.

    Attaching a modified functions.php in zipped format that should fix the error. View attachment functions.php.zip
     
    developerpanda, Sep 7, 2011 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #3
    There is an awesome Google Analytics plugin that does things like not tracking if its you browsing the site.

    I'd scrap this and use that.
     
    sarahk, Sep 7, 2011 IP
  4. WebPageMistakes

    WebPageMistakes Active Member

    Messages:
    91
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    60
    #4
    Contrary to what the instructions say on Google's site, I have mine in the footer.php file before the closing </body> tag and it works fine.

    The trouble with using a plugin to so this is it adds to the download of the page each time you add a plugin. Also, if you put it at the end of the page, should there be a problem contacting Google's site it won't stall the rendering of your page(s). (Google servers do go down. It happened a couple of years ago and it was terrible trying to surf that day because people put the script in the head.)
     
    WebPageMistakes, Sep 7, 2011 IP
  5. xira

    xira Active Member

    Messages:
    315
    Likes Received:
    8
    Best Answers:
    4
    Trophy Points:
    68
    #5
    I agree that the script should go in the footer.php page, and not the function.php page.
     
    xira, Sep 7, 2011 IP
  6. developerpanda

    developerpanda Peon

    Messages:
    104
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Exactly, I agree with both the above posts. Don't modify the functions.php, rather put it in the footer.php just before </body>
     
    developerpanda, Sep 8, 2011 IP
  7. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #7
    You have the same problem as everyone who gets this error on a mixed PHP-HTML page - you left off a tag.

    
    genesis_register_sidebar(array(
        'name'=>'Featured Posts',
        'description' => 'This is the featured posts section of the homepage.',
        'before_title'=>'<h4 class="widgettitle">','after_title'=>'</h4>'
    ));
    <script type="text/javascript">
    
      var _gaq = _gaq || [];
    
    Code (markup):
    should be
    
    genesis_register_sidebar(array(
         'name'=>'Featured Posts',
         'description' => 'This is the featured posts section of the homepage.',
         'before_title'=>'<h4 class="widgettitle">','after_title'=>'</h4>'
     ));
    [B]?>[/B]
     <script type="text/javascript">
    [B]<?php[/B]
       var _gaq = _gaq || [];
    
    Code (markup):
    You did this in more than one place.
     
    Rukbat, Sep 8, 2011 IP
  8. lamvt

    lamvt Active Member

    Messages:
    153
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #8
    <?php
    }
    
    // Add new default values for the slider
    add_filter('genesis_theme_settings_defaults', 'agentpress_slider_defaults');
    function agentpress_slider_defaults($defaults) {
    	$defaults['slider_enable'] = 1;
    	$defaults['slider_num'] = 1;
    	$defaults['slider_timer'] = 6000;
    	$defaults['slider_duration'] = 400;
    	return $defaults;
    }
    
    // Register Sidebars
    genesis_register_sidebar(array(
    	'name'=>'Featured Properties',
    	'description' => 'This is the featured properties section of the homepage.',
    	'before_title'=>'<h4 class="widgettitle">','after_title'=>'</h4>'
    ));
    genesis_register_sidebar(array(
    	'name'=>'Featured Posts',
    	'description' => 'This is the featured posts section of the homepage.',
    	'before_title'=>'<h4 class="widgettitle">','after_title'=>'</h4>'
    ));
    <script type="text/javascript">
    
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-25587143-1']);
      _gaq.push(['_trackPageview']);
    
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
    </script>
    ));
    genesis_register_sidebar(array(
    	'name'=>'Multi-Agent Page',
    	'description' => 'This is the main content area of the mult-agent page template.',
    	'before_title'=>'<h4 class="widgettitle">','after_title'=>'</h4>'
    ));
    ? 
    Code (markup):
    Should be

    <?php
    }
    
    // Add new default values for the slider
    add_filter('genesis_theme_settings_defaults', 'agentpress_slider_defaults');
    function agentpress_slider_defaults($defaults) {
    	$defaults['slider_enable'] = 1;
    	$defaults['slider_num'] = 1;
    	$defaults['slider_timer'] = 6000;
    	$defaults['slider_duration'] = 400;
    	return $defaults;
    }
    
    // Register Sidebars
    genesis_register_sidebar(array(
    	'name'=>'Featured Properties',
    	'description' => 'This is the featured properties section of the homepage.',
    	'before_title'=>'<h4 class="widgettitle">','after_title'=>'</h4>'
    ));
    genesis_register_sidebar(array(
    	'name'=>'Featured Posts',
    	'description' => 'This is the featured posts section of the homepage.',
    	'before_title'=>'<h4 class="widgettitle">','after_title'=>'</h4>'
    ));
    <script type="text/javascript">
    
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-25587143-1']);
      _gaq.push(['_trackPageview']);
    
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
    </script>
    ));
    genesis_register_sidebar(array(
    	'name'=>'Multi-Agent Page',
    	'description' => 'This is the main content area of the mult-agent page template.',
    	'before_title'=>'<h4 class="widgettitle">','after_title'=>'</h4>'
    ));
    ?>
    Code (markup):
     
    lamvt, Sep 8, 2011 IP