• Resolved officeninjas

    (@officeninjas)


    Hi Kellen,

    I am using https://www.ads-software.com/plugins/custom-post-widget, and this post type shows up on the settings page, which I enable and can see the Pixel meta box field in the edit mode of the content block, but when content block is displayed it does not insert the pixel code.

    I have a custom widget content block displaying on the homepage based on a qualifier GET parameter and I would like the FB Conversion Pixel inserted. It seems that in fb_pxl_head(), the $post_type it gets from get_post_type() is “post” with an id of the first blog post of the home feed. Don’t think it looks through other post types being displayed on the home page.

    Is there a way to insert the FB Conversion Pixel based on a widget content post type as in my use case?

    Thanks!

    P.S. Using version 1.3.1

    https://www.ads-software.com/plugins/facebook-conversion-pixel/

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

    (@officeninjas)

    Couldn’t see any other solution, so got this working for me. It’s very specific for my needs, but may help provide ideas to others.

    // --------------------------------------
    // Insert FB Pixel Conversion Code for
    // enabled post types within widgets.
    // --------------------------------------
    add_filter('widget_display_callback', 'on_widget_display_callback', 999, 3);
    function on_widget_display_callback($instance, $this, $args) {
      if (is_plugin_active('facebook-conversion-pixel/facebook-conversion-pixel.php')) {
        $post_type = 'content_block';
        $widget_name = 'Content Block';
        $fb_pxl_options = get_option('fb_pxl_options');
       // If user has enabled 'content_block' && widget is 'Content Block'
        if ( isset( $fb_pxl_options[ $post_type ] ) &&
             ('on' === $fb_pxl_options[ $post_type ]) &&
             ($args['widget_name'] === $widget_name) ) {
          $id = $instance['custom_post_id'];
          $fb_pxl_switch = get_post_meta( $id, 'fb_pxl_checkbox', true);
          // If user has chosen to insert code, insert it
          if ( 'on' === $fb_pxl_switch ) {
            $fb_pxl_code = get_post_meta( $id, 'fb_pxl_conversion_code', true);
            // Place fb pixel conersion code at bottom of footer
            $fb_pxl_code_decoded = htmlspecialchars_decode( $fb_pxl_code );
            add_action('wp_footer', function() use ($fb_pxl_code_decoded) {
              echo $fb_pxl_code_decoded;
            }, 999 );
          }
        }
      }
      return $instance;
    }

    Cool! Thanks for providing your solution for others to see.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Not working with Widget Content Blocks’ is closed to new replies.