I've been trying to figure out what I could possibly be doing wrong with this plugin I just coded, from what I see, everything should be working correctly. However, it's not doing anything at all. No errors though. Any ideas?

Here's facebook-pixel.php

Plugin Name: Facebook Pixel
Plugin URI: N/A
Description: A facebook pixel plugin coded to optimize conversions from facebook ads
Version: 1
Author: Joseph Roberts
Author URI: http://josephrobertsdesigns.com
License: GPL2

// Make sure we don't expose any info if called directly
if ( !function_exists( 'add_action' ) ) {
    echo 'Hi there!  I\'m just a plugin, not much I can do when called directly.';

define( 'FACEBOOK_PIXEL__VERSION', '1' );
define( 'FACEBOOK_PIXEL__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'FACEBOOK_PIXEL__DELETE_LIMIT', 100000 );

register_activation_hook( __FILE__, array( 'Facebook_Pixel', 'plugin_activation' ) );
register_deactivation_hook( __FILE__, array( 'Facebook_Pixel', 'plugin_deactivation' ) );

require_once( FACEBOOK_PIXEL__PLUGIN_DIR . 'facebook-pixel-run.php' );

And here's facebook-pixel-run.php


function facebook_pixel_header(){
        <!-- Facebook Pixel Code -->
        fbq('init', 'My_Facebook_Pixel_ID', {
        em: 'insert_email_variable,'
        fbq('track', 'PageView');
        <noscript><img height="1" width="1" style="display:none"
        <!-- DO NOT MODIFY -->
        <!-- End Facebook Pixel Code -->
    if( is_page('Exhibit Here') ){
        if( isset($_POST['submit']) && !isset($error) ){
            if($_POST['booth-type']=="for-profit"){ $total = 620; }else{ $total = 565; }
                $total = $total*2;
                $total = $total*3;
                $total = $total*4;
                $total = $total*5;
                $total = $total*6;
                <!-- The below method uses jQuery, but that is not required -->
                <button id="addToCartButton">Add To Cart</button>
                <!-- Add event to the button's click handler -->
                <script type="text/javascript">
                $( '#addToCartButton' ).click(function() {
                fbq('track', 'AddToCart', {
                content_ids: ['1234'],
                content_type: 'product',
                value: <?php echo number_format($total, 2, '.', ''); ?>,
                currency: 'USD'
                fbq('track', 'AddPaymentInfo');
                fbq('track', 'CompleteRegistration', {
                value: <?php echo number_format($total, 2, '.', ''); ?>,
                currency: 'USD'
            fbq('track', 'InitiateCheckout');

add_action('wp_head', 'facebook_pixel_header');

Any help would be greatly appreciated. Thank you.

  • review the function ob_end_clean()
    – Michael
    Mar 1, 2017 at 21:31
  • @Michael What do you mean review? Just for clarification I did add the ob_start(); and the ob_end_clean(); because it still wasn't outputting anything without them and I thought it may cause it to work. (Really just a shot in the dark)
    – J Robz
    Mar 1, 2017 at 21:43
  • ob_end_clean() does not output anything; just check online tutorials for what php output buffering does. not a WordPress problem.
    – Michael
    Mar 1, 2017 at 22:13
  • wp_head action filter corresponds wp_head() function call and it's used just before the HTML </head> tag. So whatever HTML it produces (without using the ob_start() and ob_end_clean()), it'll not work as expected. And with using ob_end_clean() that way is just wrong.
    – Fayaz
    Mar 1, 2017 at 23:48


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.