0

is it correct or not because it show an error when im done that

if(is_page('payment-success')) { 
    include("/wp-content/ga-ecommerce-tracking/ga-ecommerce-tracking.php");
}

3 Answers 3

1

Include accepts absolute path, relative path or a URL stream as its argument. But you are using a wrong absolute path here. Try making it to relative path ( I am assuming that you are editing a file in Wordpress root directory, if not change the path accordingly)

if(is_page('payment-success')) { 
    include("./wp-content/ga-ecommerce-tracking/ga-ecommerce-tracking.php");
}
Sign up to request clarification or add additional context in comments.

Comments

1

include expects to take a path on the filesystem as its argument. You appear to be passing in root relative URL.

3 Comments

I disagree. I don't think that path is accessible as a WP URL. But it's probably a valid filesystem path.
It starts with a /, if that is a valid filesystem path, then WordPress is installed in the system root directory! There is a web accessible directory called wp-content in the top level directory of a WordPress install, so if WordPress is installed in the webroot for a domain, then that will be an accessible URI if ga-ecommerce-tracking is put in it.
Well maybe that is his problem :). It should start with a ./
0

Try to give the full path. You can use dirname(__FILE__) to get the path of your including script and build from there with the relative path.

Also check what file_exists tells you about what you want to include.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.