• Resolved wordpressuser1973

    (@wordpressuser1973)


    Grateful for advice.

    I’m trying to include a php file–a disclaimer that needs to show up on a subset of posts.

    I’ve read related codex topics and forum discussion. Following what’s there, I gave each of the following a try in the body of the post:

    <?php include “mydisclaimer.php”; ?>

    and

    <?php get_template_part(‘mydisclaimer.php’); ?>

    (Also tried the above with the full path. This should be easy. Clearly, I’m misunderstanding the how-to.

    Again, grateful for advice.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter wordpressuser1973

    (@wordpressuser1973)

    The function that is inside of mydisclaimer.php could be called by using the Shortcode API, if you want to cast the function into a post/page.

    Make sure <?php include “mydisclaimer.php”; ?> is correctly included inside of the functions.php in the theme. You should use include_once for this case so it does not call into the page twice through the WP Loop.

    If your function name, for example, is myDisclaimerFunction() then you could add the shortcode like below inside the functions.php:
    add_shortcode( ‘mydisclaimer’, ‘myDisclaimerFunction’ );

    Then on the page/post put your shortcode in.
    [mydisclaimer]

    Must use return for the value, don’t use echo with the Shortcode API.

    Thread Starter wordpressuser1973

    (@wordpressuser1973)

    Thanks, Frank! I’m on it. Much appreciated!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘include php file’ is closed to new replies.