Skip to content Skip to sidebar

This thread is resolved. Here is a description of the problem and solution.

Problem:
The site is using the Header Footer Code Manager to load a snippet with a noindex tag into the head of the source code for specific pages. They are trying to ensure that the translated pages on your site have the same noindex tag as the original pages. The noindex tag is present in the original page's code, but it is missing in the translated versions.
Solution:
To include the noindex tag in the translated pages using WPML, you need to modify the code in the header-footer-code-manager plugin. Follow these steps:
1. Open the

.../wp-content/plugins/header-footer-code-manager/99robots-header-footer-code-manager.php

file.
2. Locate line 550.
3. Open the .../wp-content/plugins/header-footer-code-manager/99robots-header-footer-code-manager.php file

Look for line 550

Replace:

                        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:

                        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;

This modification ensures that the noindex tag is applied to translated pages as well. If this solution does not resolve your issue or seems outdated, please check the related known issues and confirm that you have installed the latest versions of themes and plugins. If necessary, do not hesitate to open a new support ticket.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 16 replies, has 1 voice.

Last updated by Andreas W. 5 months, 4 weeks ago.

Assisted by: Andreas W..

Author Posts
January 17, 2025 at 12:48 pm #16606152

alexZ-17

Re 1: Yes, it is the case
Re 2: It is OK
Re 3: I do not grasp it entirely – at the moment it is not actual, but I will study the issue and come back if needed
I will contact the author of HFCM.

I think your workaround makes more than you expected (I report the implementation in PROD):
The Page List in Snippet shows all translated pages, which correspond to original pages for the Snippet (in this case – having NOINDEX tag), cf. enclosure

The only thing to do is to update the Snippet – I do not need even to choose pages, very comfortable and reliable!
The issue of many pages seems to me to be minor.

Re another workaround:
Should I use the original hfcm-add-edit.php and make the replace in 99robots-header-footer-code-manager.php?

Last but not the least:
I am really impressed by your support and it would be my pleasure to inform your management about my opinion, subject you do not oppose it, like following:
Email: support.manager@onthegosystems.com
Dear Amit,
It is my pleasure to inform you about excellent support by Andreas.
The problems he solved – incompatibility of HFCM plugin which I use to add NOINDEX tag – was really amazing.
Before my retirement I have had decades long experience of support with ORACLE and SAP (not in Websites) – and I can say that Andreas is fully competitive with these IT giants.

best
Alex

Noindex-Snippet. PageList_20250117.png
January 17, 2025 at 4:01 pm #16607357

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Thank you very much for your kind words, Alex!

I forgot to mention, when it comes to the workarounds, please stick only with one of them. If you use the second one, make sure to remove the first one, so that you do not run into further issues.

I spoke to the Compatibility Team yesterday and we have looped in our Partnership Manager (Dean) and asked him to try to reach the author of HFCM.

Hopefully, we can obtain cooperation on this matter.