Insert PHP in Content Area When PHP Includes a Shortcode
-
I’m using a PHP function that dynamically displays what phone number a website visitor should call based on whether or not a cookie has been set by the visitor arriving at the site through an affiliate link. The function is working fine outside of page and post content areas, such as in header.php and in an advanced text widget in the sidebar.
Inside the content area however it produces nothing. All the rest of the content before and after where the phone number should be is there, but the phone number is nowhere to be seen. I have installed the plugin “Allow PHP in Posts and Pages” for inserting my PHP code into the page/post content area. Here is what I’m using inside the content area to call my function:
[php]<?php display_phone_number (); ?>[/php]The
[php]shortcode is what the plugin calls for to insert php code into the content area.Here is the function
display_phone_numberthat is working fine elsewhere on the site:function display_phone_number () {<br /> if(!isset($_COOKIE['ap_id'])) {<br /> echo "(800) 123-4567";<br /> } else {<br /> echo do_shortcode( '[wp_affiliate_referrer_details info="phone"]' );<br /> }<br /> }I suspect the problem may be that I’m already having to use a shortcode
[php][/php]to insert the PHP, and then the actual PHP I’m inserting calls a function that incorporates another shortcode.Here is the function that is called by the shortcode
[wp_affiliate_referrer_details info="phone"]:function wp_affiliate_referrer_details_handler($atts){<br /> extract(shortcode_atts(array(<br /> 'ap_id' => '',<br /> 'info' => '',<br /> ), $atts));<br /> if(empty($ap_id)){//Set it to current referrer<br /> $ap_id = wp_affiliate_get_referrer();<br /> }<br /> if(empty($ap_id)){<br /> return AFF_NONE;<br /> }<br /> return wp_aff_get_affiliate_details($ap_id,$info);<br /> }If I knew how to incorporate into my function display_phone_number the actual code for the function
wp_affiliate_referrer_details_handlerand tell it that I want to look up “phone”, rather than using the following…do_shortcode( '[wp_affiliate_referrer_details info="phone"]' )…then I would do so and see if that solved the problem, but I don’t know how. Does anyone know how I can make this work inside my page/post content area just like it’s already working outside of the content area?
Thanks!
The topic ‘Insert PHP in Content Area When PHP Includes a Shortcode’ is closed to new replies.