Take the 2-minute tour ×

Does wordpress ignore foreign php code? I'm attempting to throw a function call in an external class below this line on root index.php of wordpress

/** Loads the WordPress Environment and Template */

Here is my function call

//Create traffic object for tracking who is hitting this page
$site_traffic = new Site_Traffic();

Here is what happens within this function.

  • Sets the correct database, table, user name, password
  • Checks the querystrings parameters for special cases to track in the function
  • If the function sees a special parameter case it inserts it into a site-traffic table by creating a sql statement and then calling my mysqliconnection library
  • The library then takes the sql statement, the database, table, username and password and inserts the site-traffic call into the corresponding table.

I use this on all my pages outside of wordpress and it works fine and yet on the index.php page it does not work at all.

I'm able to echo out the sql statement, database, table, username and password from the wordpress index.php page so I know it is getting to that point.

EDITED: Made the issue more apparent and specific

share|improve this question
Don't be sorry, be specific: stackoverflow.com/help/mcve –  brasofilo Apr 14 at 0:49
If you are editing the core index.php file for Wordpress, you shouldn't. If you're editing the index.php file for your theme, it might not work how you expect... the index.php file is not usually used to display a page. Depending on which page or template is used, your theme may use a file such as page.php or single.php or front-page.php. Perhaps this will help: codex.wordpress.org/Template_Hierarchy –  Tim Hallman Apr 14 at 4:32

1 Answer 1

Put this into a custom plugin or your theme's functions.php.

Here's how I'd go about it:

Create the following file (including directory): /your-wp-root/wp-content/plugins/wpse-site-traffic/wpse-site-traffic.php

 * Plugin Name: WPSE Site Traffic
 * Description: Woohoo - Site Traffic moved to a plugin.
 * Version: 1.0
 * Author: Dom

// Load Site_Traffic Class.
require_once( ABSPATH . 'modules/Site-Traffic/Site-Traffic.php' );

 * Create traffic object for tracking who is hitting this page. Hook
 * it into 'plugins_loaded' to run early.
function wpse_site_traffic_load() {
    $site_traffic = new Site_Traffic();
add_action( 'plugins_loaded', 'wpse_site_traffic_load' );
share|improve this answer

Your Answer


