Skip to content Skip to sidebar

Open

Topic Tags: Compatibility

Overview of the issue

When using the Header Footer Code Manager plugin to insert snippets into specific pages, the display conditions are not correctly applied to translated pages when using WPML. This results in missing snippets, in the translated versions of pages.

Workaround

Please, make sure of having a full site backup of your site before proceeding.

  • Open the …/wp-content/plugins/header-footer-code-manager/99robots-header-footer-code-manager.php file
  • Look for line 550.
  • Replace:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    case 's_pages':
        $is_not_empty_s_pages = self::hfcm_not_empty( $scriptdata, 's_pages' );
        if ( $is_not_empty_s_pages ) {
            // Gets the page ID of the blog page
            $blog_page = get_option( 'page_for_posts' );
            // Checks if the blog page is present in the array of selected pages
            if ( in_array( $blog_page, json_decode( $scriptdata->s_pages ) ) ) {
                if ( is_page( json_decode( $scriptdata->s_pages ) ) || (!is_front_page() && is_home()) ) {
                    $out = self::hfcm_render_snippet( $scriptdata );
                }
            } elseif ( is_page( json_decode( $scriptdata->s_pages ) ) ) {
                $out = self::hfcm_render_snippet( $scriptdata );
            }
        }
        break;
  • With:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    case 's_pages':
        $is_not_empty_s_pages = self::hfcm_not_empty( $scriptdata, 's_pages' );
        if ( $is_not_empty_s_pages ) {
            // WPML workaround for compsupp-7802
            $original_ids = json_decode( $scriptdata->s_pages);
            foreach ( $original_ids as $original_id ) {
                $translated_ids[] = apply_filters( 'wpml_object_id', $original_id, 'page');
                }
            // Gets the page ID of the blog page
            $blog_page = get_option( 'page_for_posts' );
            // Checks if the blog page is present in the array of selected pages
            if ( in_array( $blog_page, json_decode( $scriptdata->s_pages ) ) ) {
                if ( is_page( $translated_ids ) || (!is_front_page() && is_home()) ) {
                    $out = self::hfcm_render_snippet( $scriptdata );
                }
            } elseif ( is_page( $translated_ids ) ) {
                $out = self::hfcm_render_snippet( $scriptdata );
            }
        }
        break;

Leave a Reply

Please stay on topic and be respectful to others. If you need help with issues not related to this post, use our Support Forum to start a chat or submit a ticket.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>