[noindex] shortcode not functioning as expected
-
Hello. Just purchased and installed Premium plugin to hide certain content from search results. I’m using Divi and have built sidebar menus as Global Layouts. I don’t want the text from those menus to be indexed or returned as results. For example, there is one page on the site that mentions “wire transfers”, but there are several other pages that have “Wire Transfers” in the Global layout menus I’ve built. I’ve tried using [noindex]…[/noindex] around the text in the menus, but it’s not having any effect. I’ve also listed those Layouts (as they have a unique post ID) in the Relevanssi settings to be excluded. Is there a way to make this work?
The page I need help with: [log in to see the link]
-
Since you’ve paid for customer support, please use the Premium support form.
Anyway, since this is NOT a Premium-related question and only related to features available in the free version, I can answer this here (I’m not allowed to answer Premium questions here, the forum moderators will lock threads about Premium features).
Using the [noindex] shortcode is unlikely to work in this case, it’s meant for just blocking parts of text from being indexed. In the case of menus on pages like this, it’s best to filter out the menu from the page before Relevanssi sees it. The exact method depends on how the menu is implemented.
There’s for example the
relevanssi_post_content
filter hook, which can be used to filter out the post content before Relevanssi sees it. Is the sidebar menu added to the page with a shortcode? If so, that filter hook happens before the shortcodes are expanded, so it’s easy to just pluck out the shortcode. If not, then it may require some changes…But if you’re not using Gutenberg, you can easily check it out. Add this to your theme functions.php and go save a post that has a menu:
add_filter( 'relevanssi_post_content', 'rlv_remove_menu' ); function rlv_remove_menu( $content ) { var_dump( $content ); exit(); }
When you save the post, this should print out the contents of the post as Relevanssi sees it. How does the menu appear there?
I guess I wasn’t clear. What I am calling menus are actually just text. It’s in a regular text module, and looks like:
[noindex]<p><strong><a href="https://www.txdpscu.org/accounts/">Accounts</a></strong></p><p><a href="https://www.txdpscu.org/accounts/savings-accounts/">Savings Accounts</a></p>...<p><a href="https://www.txdpscu.org/convenience/forms/">Forms</a></p>[/noindex]
Where is the text? Is it part of the post content, or a separate entity somewhere else? I don’t know what a “Global layout menu” is, how is it added on the page? If it’s just text in the post content, the [noindex] tag should work without problems, but if it’s coming from somewhere else, it’s a different case.
Divi works like this. In their editor, everything is placed on the page with a module (text module, image module, slider, whatever). As you are building pages, you can designate modules/layouts to be saved to a library to be used over and over. If you mark it as a “Global” module, it will always be the same on each page that it is used. So, the text module that I am trying to hide is a Global module, but really just a block of text on the page. If you want me too, I’m happy to do a Zoom session with you and show you how it works.
Yes, which is why I asked. The block of text on the page probably isn’t a block of text in the post content (since it’s a global), but instead is stored somewhere else than the page, and the place where it’s stored isn’t covered by the noindex tag.
When the global module is added on the page, knowing Divi it’s probably represented by a shortcode – blocking that shortcode, or whatever it is Divi uses to insert the global block on the page, is the best way to remove the menu from Relevanssi index.
So, again: if you’re not using Gutenberg (are you?), try adding this and saving a post with the menu, and report to me how the menu shows up in the result:
add_filter( 'relevanssi_post_content', 'rlv_remove_menu' ); function rlv_remove_menu( $content ) { var_dump( $content ); exit(); }
Does it appear as plain text (in which case does it have a CSS class or something like that so we could recognise it and remove it?) or does it appear as a shortcode or something else?
-
This reply was modified 5 years, 8 months ago by
Mikko Saari.
Not using Gutenberg. Added the above code to functions.php. No change in the way my page displays. No change in the search results. If I change what I want blocked to an actual menu, would it then be hidden from search results?
FYI – I did a test to put the content on the page as a menu, hid my text block and saved the page. I then did a search and it omitted the page correctly. So, I could go back and set up menus and redo that section of all the pages (around 80), but would really like to understand/use the noindex shortcode.
Also FYI – You are correct about Divi using shortcodes, so could that be messing up the way the plugin functions?
More FYI – whatever I was doing earlier with the functions.php hack and all was not working properly. I started getting some weird output upon saving pages, and then those pages (without actually editing them, just clicking the Update button) began to dissappear from the serach results. As another test, I opened and saved the few pages that I did want to show up, updated them (again without changing anything) and presto! They also were removed from the search results. So, had to restore site from backup. Thoughts?
It’s not supposed to change how the page displays or the search results: the effects should be clearly visible when you save the page – like I said and as you noticed.
That code prevents saving the pages, but that’s ok, because all I wanted to know is how the menu gets added on the page; after that you can and should remove the code, so that saving pages works again. There was no need for restoring from backup; there’s nothing in the backup that was lost. You can get posts back in the search results by saving them again after the code is removed.
So please, insert the code again, go save a post with a menu, report the results, and then remove the code (and save that post again). Once you do that, I can probably tell you how to get rid of the menus. Divi using shortcodes is not a problem, it actually makes solving this much easier. I just need to know the exact shortcode for the menu.
Here is that data dump, to just past the mmenu. Notice it’s not showing the [noindex] code??
string(26795) "[et_pb_section bb_built="1" fullwidth="on" _builder_version="3.0.47" next_background_color="#000000" inner_width="auto" inner_max_width="none"][et_pb_fullwidth_image src="https://www.txdpscu.org/wp-content/uploads/2019/02/Holiday-Account-B.jpg" _builder_version="3.19.15" /][/et_pb_section][et_pb_section bb_built="1" use_custom_width="on" width_unit="off" custom_width_percent="89%" use_custom_gutter="on" gutter_width="2" specialty="on" _builder_version="3.19.4" custom_padding="0|0px|54px|0px|false|false" prev_background_color="#000000" next_background_color="#000000" inner_width="89%" inner_max_width="89%"][et_pb_column type="1_4"][et_pb_text admin_label="Accounts Menu" module_class="mini_navs" _builder_version="3.19.18" text_font_size="16px" custom_margin="66px|||" global_module="171" saved_tabs="all" hover_enabled="0" disabled_on="on||" disabled="off"] Accounts Savings Accounts Checking Accounts Related Shared Branches ATMs Change of Address Check Reorder Wire Transfer Fee Schedule Rates Calculators Who Can Join Convenience Online Banking Bill Pay e-Services Direct Deposit Mobile Banking Forms [/et_pb_text][/et_pb_column][et_pb_column type="3_4" specialty_columns="3"][et_pb_row_inner custom_padding="0|0px|29.6875px|0px|false|false" _builder_version="3.0.47"][et_pb_column_inner type="4_4" saved_specialty_column_type="3_4" custom_padding__hover="|||" custom_padding="|||" saved_specialty_column_type="3_4"][et_pb_post_title admin_label="Page Title" meta="off" featured_image="off" _builder_version="3.19.4" title_font="|600|||||||" title_text_color="#b21e28" title_font_size="48px" title_line_height="1.7em" border_width_bottom="2px" border_color_bottom="#cccccc" text_orientation="center" custom_margin="15px|||" custom_padding="0px|||" global_module="170" saved_tabs="all" /][et_pb_text _builder_version="3.19.18" text_font_size="16px" header_4_font="|600|||||||" header_4_text_color="#008996" header_5_font="|600|||||||" header_5_text_color="#008996"] Jump-start your Holiday Savings
Yeah, Divi is probably stripping the shortcodes off the menu contents.
But this seems easy: the menu is wrapped inside a [et_pb_text admin_label=”Accounts Menu” module_class=”mini_navs” _builder_version=”3.19.18″ text_font_size=”16px” custom_margin=”66px|||” global_module=”171″ saved_tabs=”all” hover_enabled=”0″ disabled_on=”on||” disabled=”off”][/et_pb_text] shortcode block. We just remove that. This should do the trick, added to your theme functions.php or a custom plugin:
add_filter( 'relevanssi_post_content_before_tokenize', 'rlv_remove_menu' ); function rlv_remove_menu( $content ) { $content = preg_replace( '~\[et_pb_text admin_label="Accounts Menu".?\[/et_pb_text\]~', '', $content ); return $content; }
Thanks again. Still not working. Still getting results from those pages with the Accounts Menu. Added code into my header.php
This is an indexing setting, so it won’t take effect until you reindex. Sorry I forgot to mention that. Does it still not work if you reindex? Also, header.php is not a good place, as it doesn’t get executed there. Use functions.php, because that runs every time, also in the admin backend.
Sorry. I meant to write functions.php. That is where I put the code. I’ve re-indexed and deleted server cache and it’s still not working??
Don’t know, that should work –?I tried this on my test site, and it does remove the shortcode and the contents before indexing. You can check how it’s working by replacing the code with this:
add_filter( 'relevanssi_post_content_before_tokenize', 'rlv_remove_menu' ); function rlv_remove_menu( $content ) { $content = preg_replace( '~\[et_pb_text admin_label="Accounts Menu".?\[/et_pb_text\]~', '', $content ); var_dump( $content ); exit(); return $content; }
That will again print out the post contents when you go save a post. Does the menu still appear in the page content? (Once you’ve done checking, you can remove the
var_dump(); exit();
line.) -
This reply was modified 5 years, 8 months ago by
- The topic ‘[noindex] shortcode not functioning as expected’ is closed to new replies.