0

I have the php file and in that I am linking a HTML file.

include 'practice.html';

In the HTML file I have a few CSS files linked.

    <link href="practice1.css" rel="stylesheet" />
    <link href="practice2.css" rel="stylesheet" />

Now, what is happening is the Page Template is displaying only the HTML part and not able to access the CSS files.

How can I possibly use CSS files?

PS : ALL my PHP, HTML, and CSS files are under the same folder (wordpress\wp-content\themes\*).

4
  • You should use wp_enqueue_style to add your stylesheets: codex.wordpress.org/Function_Reference/wp_enqueue_style Commented May 30, 2015 at 18:35
  • @jeroen I have my CSS files already linked to the HTML file, so do I need to link it again in the PHP file when I am already linking the HTML file? Commented May 30, 2015 at 18:46
  • You should try to follow WordPress's method of including files and assets in general to avoid running into problems later on. Commented May 30, 2015 at 18:47
  • @jeroen So where am I wrong? I am creating a php file and linking the HTML file (which has some css files in it). Commented May 30, 2015 at 18:49

2 Answers 2

1

On your PHP template page, use:

<?php require(TEMPLATEPATH.'\practice.html'); ?>

And on your HTML page, use:

<link href="\wordpress\wp-content\themes\YourThemeName\practice1.css" rel="stylesheet">
<link href="\wordpress\wp-content\themes\YourThemeName\practice2.css" rel="stylesheet">

Make sure to replace YourThemeName with, your theme's name. And also to provide the correct path of where your CSS files are located.

If your wondering about what TEMPLATEPATH does, it provides the path to the template in use by WordPress so you do not have to type out the full path ex. \wordpress\wp-content\themes\YourThemeName\

Are you working on a local server or a live website? Depending on which one it is, you will have to change up the paths.

Example:

For a live website use:

/wordpress/wp-content/themes/YourThemeName/

or

For a local server use:

\wordpress\wp-content\themes\YourThemeName\
Sign up to request clarification or add additional context in comments.

10 Comments

When I am including the above in the php template page it is giving error : ` Failed opening required 'C:\wamp\www\wordpress/wp-content/themes/twentyfifteenpracitce.html'`
I got it when I removed the "Templatepath" from <?php require(TEMPLATEPATH.'practice.html'); ?>
You should keep "TEMPLATEPATH". What was missing in the above code snippet was a forward slash "/". ex. <?php require(TEMPLATEPATH.'/practice.html'); ?> I've updated my code snippet to use a forward slash in the path.
Even then it gives error. See the ` \` changes to / after wordpress directory, thus not giving the correct location.
But why do we use TEMPLATEPATH when it works fine even if we do not use it.
|
0

try using Include PHP function for including HTML file and for the CSS you can simply use echo

<?php


echo '<link href="practice1.css" rel="stylesheet">';
include('practice.html');

?>

2 Comments

Does not work. It is able to display the HTML file (but not the CSS files that are linked to the HTML file).
try ECHOing <link /> tag with full pathname ie echo <link href="\wordpress\wp-content\themes\YourThemeName\practice1.css" rel="stylesheet">

Your Answer

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