• DaveyJake

    (@daveyjake)


    Philipp,

    In my functions.php file, I’m attempting to call custom-pos-header.php which contains only one line: <?php echo do_shortcode('[moduleposition id="1"]'); ?>

    I keep getting this message: Fatal error: Call to undefined function do_shortcode() in /www/mySite/wp-content/themes/myTheme/inc/custom-pos-header.php on line 1

    After Googling for a couple days, I came across numerous suggestions saying to do it through Ajax. Here’s the entry I made in my functions.php file:

    // embed the javascript file that makes the AJAX request
    wp_enqueue_script( 'load-mobile-header-ajax', get_template_directory_uri() . '/js/ajax.js', array( 'fnd-jquery' ) );
    wp_localize_script( 'load-mobile-header-ajax', 'myAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
    // THE AJAX ADD ACTIONS
    add_action( 'wp_ajax_load_mobile_header', 'load_mobile_header' );
    add_action( 'wp_ajax_nopriv_load_mobile_header', 'load_mobile_header' ); // need this to serve non logged in users
    function load_mobile_header(){
    	include('../wp-content/plugins/module-positions/module-positions.php');
    	$mobile_header = get_template_directory_uri().'/inc/custom-pos-header.php';
    	return $mobile_header;
    	die();
    }

    Here is the entry I’ve added to my ajax.js file:

    jQuery.ajax({
      // previous type was "POST"
      type:"GET",
      url: ajaxurl,
      data: {
        action : "load_mobile_header"
      },
      success:function(data){
        window.console.log(data);
      },
      error:function(errorThrown){
        window.console.log(errorThrown);
      }
    
    });

    Any ideas on what I’m doing wrong?

    https://wordpress.org/plugins/module-positions/

  • The topic ‘Calling From Functions.php’ is closed to new replies.