• Resolved mlaw93

    (@mlaw93)


    Is there a way to enable php execution in AddFunc Head & Footer Code?
    I need some dynamic jQuery in the footer.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter mlaw93

    (@mlaw93)

    I found a way, although now I have to be careful with upgrades – I added a method called aFhfc_execute_php. I call it before returning the final html.

    /*
    F R O N T E N D O U T P U T
    ===============================
    Outputs the head and footer code for individual posts
    */
    function aFhfc_execute_php($html){
    if(strpos($html,"<"."?php")!==false){ ob_start(); eval("?".">".$html);
    $html=ob_get_contents();
    ob_end_clean();
    }
    return $html;
    }
    function aFhfc_head_output( $post ) {
    $aFhfc_head_code = get_post_meta( get_the_ID(), 'aFhfc_head_code', true );
    echo aFhfc_execute_php($aFhfc_head_code)."\n";
    }
    add_action('wp_head', 'aFhfc_head_output');
    function aFhfc_footer_output( $post ) {
    $aFhfc_footer_code = get_post_meta( get_the_ID(), 'aFhfc_footer_code', true );
    echo aFhfc_execute_php($aFhfc_footer_code)."\n";
    }
    add_action('wp_footer', 'aFhfc_footer_output');
    Plugin Author Joe Rhoney

    (@joerhoney)

    Well done! Yeah, there is no way as is, so an implementation such as this one would be necessary. If you want to avoid update notifications so you don’t accidentally update it, you can do this:

    1. Backup the code you have in all of the AddFunc Head & Footer Code fields (in a text document), don’t forget individual Page/Post meta fields
    2. Rename the plugin directory (whatever you want, but no spaces)
    3. Rename the main plugin file (addfunc-head-footer-code.php in this case), giving it the exact same name you gave the directory
    4. Paste your code back into their respective fields

    This basic procedure works with all plugins and you will no longer see update notifications. However, some plugins may not function properly afterwards.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Execute PHP in AddFunc Head & Footer Code’ is closed to new replies.