WordPress.org

Support

Support » How-To and Troubleshooting » PHP include is not working in page

PHP include is not working in page

  • shaijuelayidath

    @shaijuelayidath

    I have created a JQuery Slider page (slider.php) it is having a library and a javascript function. When I am include it in the header.php of wordpress it is working well. But when I include it in the wordpress page through dashboard it is not working. But I can successfully include other external php files here. What is the problem…?

Viewing 15 replies - 1 through 15 (of 18 total)
  • wpsecuritylock

    @wpsecuritylock

    You cannot write to “include” in a page or post. You would want to create a shortcode or use a plugin to do that.

    shaijuelayidath

    @shaijuelayidath

    I was tring this after installed a plug in (PHP-Execution). By this plugin I included an external file with a form, it is fantastically worked. But this is only not working

    My file name is slider.php, I used the following code to insert my slider file.

    <?php include (“wp-content/themes/twentyeleven/slider.php”);?>

    The same above code is working with the header and footer. This is not working when I am puting it in the page through dashboard, that is the problem…

    wpsecuritylock

    @wpsecuritylock

    This is a guess, but try putting the full path to the file

    <?php include (“http://yourdomain.com/wp-content/themes/twentyeleven/slider.php”);?>

    Chris Olbekson

    @c3mdigital

    Level 12 Bug Squasher & Forum Moderator

    This is a guess, but try putting the full path to the file

    <?php include (“http://yourdomain.com/wp-content/themes/twentyeleven/slider.php”);?>

    You can not use urls as php includes unless that is turned on your php.ini which by the way is VERY INSECURE!

    If you need to include a php file use get_template_part(). . Or create a shortcode.

    Trying to use a plugin that allows php execution probably not a good idea unless you have a very good understanding of the programming language.

    shaijuelayidath

    @shaijuelayidath

    thanks for suggestion…
    i heard lot about shortcode but i did’nt understand it, because i am very new to javascript and php. Which is the method of ‘shortcode’ i have to put instead of the php include

    My include code again below:
    <?php include (“wp-content/themes/twentyeleven/slider.php”);?>

    wpsecuritylock

    @wpsecuritylock

    I agree with Chris!

    I don’t use any plugins that embed php code in post, pages or widgets.

    Probably the easiest is to use short codes.

    shaijuelayidath

    @shaijuelayidath

    i started to read about shortcode and feel it is much developer oriented one. Is the shortcode is vary as per the purpose, or is it has a general code for implementation…whatever i’ll refer about it. But now can you help me to write a shortcode for include an external file in a wordpress page through dashboard.

    Chris Olbekson

    @c3mdigital

    Level 12 Bug Squasher & Forum Moderator

    This should work depending on the code in slider.php.

    add_shortcode( 'myslider', 'slider_sc_handler' );
    function slider_sc_handler() {
    		ob_start ();
    		include_once( get_stylesheet_directory() .'/slider.php' );
    		$content = ob_get_clean();
    		return $content;
    }

    Now just add [myslider] to the content.

    shaijuelayidath

    @shaijuelayidath

    When I use this shortcode should I uninstall the plugins

    Chris Olbekson

    @c3mdigital

    Level 12 Bug Squasher & Forum Moderator

    Why would you? Just add that shortcode function to your themes functions.php file.

    shaijuelayidath

    @shaijuelayidath

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]

    The code i used in ‘slider.php’ is given below :

    ————————- slider.php —————————–

    <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/wp-content/themes/twentyeleven/js/jquery-1.2.6.min.js"></script>
    <script type="text/javascript">
    /***
        Simple jQuery Slideshow Script
        Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
    ***/
    function slideSwitch() {
        var $active = $('#slideshow IMG.active');
        if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
        // use this to pull the images in the order they appear in the markup
        var $next =  $active.next().length ? $active.next()
            : $('#slideshow IMG:first');
        // uncomment the 3 lines below to pull the images in random order
        // var $sibs  = $active.siblings();
        // var rndNum = Math.floor(Math.random() * $sibs.length );
        // var $next  = $( $sibs[ rndNum ] );
        $active.addClass('last-active');
        $next.css({opacity: 0.0})
            .addClass('active')
            .animate({opacity: 1.0}, 1000, function() {
                $active.removeClass('active last-active');
            });
    }
    $(function() {
        setInterval( "slideSwitch()", 2000 );
    });
    </script>
    
    <div id="slidersection">
    <div id="slideshow">
        <img src="wp-content/themes/twentyeleven/images/transition1.jpg" alt="Slideshow Image 3" style="opacity: 1; " class="">
        <img src="wp-content/themes/twentyeleven/images/transition2.jpg" alt="Slideshow Image 3" style="opacity: 1; " class="">
        <img src="wp-content/themes/twentyeleven/images/transition3.jpg" alt="Slideshow Image 3" style="opacity: 1; " class="">
        <img src="wp-content/themes/twentyeleven/images/transition4.jpg" alt="Slideshow Image 4" style="opacity: 1; " class="">
        <img src="wp-content/themes/twentyeleven/images/transition5.jpg" alt="Slideshow Image 5" style="opacity: 1; " class="active">
    
    </div></div>

    ——————————————————————-

    Now i put the code you given at last of the ‘functions.php’
    ————————————————————-

    add_shortcode( 'myslider', 'slider_sc_handler' );
    function slider_sc_handler() {
    		ob_start ();
    		include_once( get_stylesheet_directory() .'/slider.php' );
    		$content = ob_get_clean();
    		return $content;
    }

    ————————————————————–
    then i added [myslider] in my page..but shows the text as it is..
    is it required to set my path before the file name..or is any specific place to add the shortcode in functions.php

    Moderator Jan Dembowski

    @jdembowski

    Volunteer Mod. & Brute Squad

    shaijuelayidath, you really need to learn to use the code button…

    http://codex.wordpress.org/Forum_Welcome#Posting_Code

    shaijuelayidath

    @shaijuelayidath

    thank you for suggestion

    shaijuelayidath

    @shaijuelayidath

    Hi Chris Olbekson,

    Thank youuu very very much…it works….the code you given me rocked…it is fineeee….
    It was my experiment to convince the possibilites of ‘wordpress’
    to one of my friend for a small project.
    You really helped and inspired me instantly even if
    my question is below average.
    I visited you excellent site also.
    You perfectly done the job of a consultant and a
    real worthfull person here.
    For my future doubts can i ask to you,
    only as per your convenience…

    Prabhak

    @prabhak

    Hello Everyone, 🙂

    The reason I’m posting in this thread is because I noticed some really helpful people solve Shai’s problem.

    The strangest thing; I migrated my wordpress from an old domain finger monkey wire and then uploaded it to my new domain http://www.athenatechs.com

    Now when I visit the site the browser tab displays says Finger Monkey Wire while the url is athenatechs.com

    I’ve used search and replace in the migrated database to replace the finger monkey wire url with athenatechs and have been through all the theme files including header and index.php

    This is a huge mystery to me anyone faced this phenomenon before?

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘PHP include is not working in page’ is closed to new replies.