If including a file by name doesn’t work, you probably need the full path:
<?php include( get_stylesheet_directory() . '/_dropdowns.php'); ?>
Since I don’t know what theme you are using or what your code does, I’ll assume twentythirteen and ignore potential issues with the loading order of WordPress. Depending on what _dropdowns.php does this loading order may make a difference.
Method 1: Requires minimum familiarity with php but loads your php file pretty much at the last possible moment, which makes it vulnerable to any loading order issues. Try using the plugin: “PHP code snippets”. This provides a shortcode within which you can run php. It looks like you could put an insert or require statement for your php file within that shortcode.
Assuming the plugin works as advertised:
1) Install it
2) Insert this code in your home page:
[insert_php]include( get_stylesheet_directory() . '/_dropdowns.php');[/insert_php]
Method 2: Requires a little more comfort with php. Detect the home page and load “_dropdowns.php” only if the current page is the home page.
Put the following code inside the WordPress loop, so it is likely to be in a page or post template file or in the content.php file (in your child theme), which is a template part loaded within the loop:
<?php
...
$postID = get_the_ID();
$postTitle = get_the_title( $postID );
...
?>
...
<?php if($postTitle == "Home"){ // Or whatever your home page title is...
include( get_stylesheet_directory() . '/_dropdowns.php');
<?php } ?>
Method 3: Requires a little more PHP comfort. Encapsulate the code in method 2 in a function in functions.php and call it from either the page/post template file or the content.php file.
Method 4: Requires the most PHP knowledge. If the php file simply contains a function you want to execute on the page, I would tend to rewrite /_dropdowns.php as a custom shortcode.
-
This reply was modified 7 years, 11 months ago by
feralreason.
-
This reply was modified 7 years, 11 months ago by
feralreason.