-
AuthorPosts
-
August 24, 2018 at 11:30 am #1001137
Dear support,
is there a way to change the accordion title to <h2>? Because of SEO optimization.
Thanks for any helpAugust 24, 2018 at 12:32 pm #1001174put this in your functions.php of your child-theme:
function replace_tags_with_tags(){ ?> <script> (function($) { function replaceElementTag(targetSelector, newTagString) { $(targetSelector).each(function(){ var newElem = $(newTagString, {html: $(this).html()}); $.each(this.attributes, function() { newElem.attr(this.name, this.value); }); $(this).replaceWith(newElem); }); } replaceElementTag('h3.aviaccordion-title', '<h2></h2>'); }(jQuery)); </script> <?php } add_action('wp_footer', 'replace_tags_with_tags');
August 24, 2018 at 12:36 pm #1001176PS
this linereplaceElementTag('h3.aviaccordion-title', '<h2></h2>');
could be added by new lines in the same way (‘tag to replace’, ‘new tag’)
so you can use this for more replacementsAugust 24, 2018 at 1:06 pm #1001191Hey Guenni007,
thanks for your help, I put the code in my childthemes functions.php. Where can i see if it works, if it is h3 now?
It is located in the homepage if you scroll down proditool.deAugust 24, 2018 at 1:35 pm #1001205you want from h3 to h2 a change!
look to your source code of your page – allmost all modern browsers got developer tools
most you can go with your mouse over the element to inspect and then press context button of your mouse ( most right mouse button) – there will be something like inspect ( or inspect element) or so.August 24, 2018 at 1:38 pm #1001206ok i see your homepage now. – but where is the accordion ? – pleas look to your page and tell me the name of the alb element you used!
August 24, 2018 at 1:40 pm #1001209Thanks, i know that but in the source i don´t see any h2 tag? That´s why i am asking. I didn´t see a h3 tag before in the accordion-headline as well
August 24, 2018 at 1:43 pm #1001213Ooops, i was too fast :-)
If you scroll down to the element with the green gradient background, section-id is “seotext”August 24, 2018 at 1:43 pm #1001214if you mean that toggler –
“Warum sie Diamantwerkzeug kaufen sollten” etc.this is not possible – it will work with that code above and:
as additional line:replaceElementTag('.togglecontainer p.toggler', '<h3></h3>');
but toggler is predefined over p tag – so there will be a lot to change in css to reach the toggle effect then.
August 24, 2018 at 1:48 pm #1001217Yes thats the right toggler, but after that additional line it seems to work now. The toggle effect works as well.
So thanks for your help!August 24, 2018 at 1:55 pm #1001224Hi dondela,
Glad Guenni007 helped you to get it working.
If you need further assistance please let us know.
Best regards,
VictoriaAugust 24, 2018 at 3:24 pm #1001272Yes – it is hard to make a statement only about the simulation in the developer tools.
So i’m glad that it works for you nowAugust 25, 2018 at 6:56 am #1001487April 13, 2020 at 8:46 pm #1203345Hello,
I need the titles of my accordion element to be H2.I do followed the instructions in this post but it did not seem to work, I don’t understand why since I have added the code above in the function.php of my child theme.
Here’s the page where I’ve inserted the accordion element: https://prof-ilaure.fr/foire-aux-questionsDoes anyone see why it doesn’t work?
- This reply was modified 4 years, 8 months ago by rvga.
April 14, 2020 at 3:38 pm #1203626Hi rvga,
Can you give us temporary admin access to your website in the private content box below, so that we can have a closer look?
Best regards,
VictoriaApril 20, 2020 at 10:10 am #1205439This reply has been marked as private.April 21, 2020 at 11:58 am #1205747Hi,
Sorry for the confusion. We replaced the selector parameter of the script in the functions.php file with “.toggler” instead of the old one. The toggler title is now h2.
replaceElementTag('.toggler', ' <h2></h2> ');
Best regards,
IsmaelApril 21, 2020 at 3:12 pm #1205816It works perfectly thanks to you Ismael.
And what would be its css code to change the H2 font-size please ?
April 21, 2020 at 6:59 pm #1205924Hi,
h2{ font-size:20px; }
Adjust the size to what you need.
Best regards,
Jordan ShannonApril 22, 2020 at 9:38 am #1206089Sorry Jordan
I meant that I want to change only the size of the H2 of my accordion element.
Your code is going to change the size of all my H2s in the website, from what I understand, don’t I?April 22, 2020 at 7:29 pm #1206346Hi rvga,
Here is the code you can put in Enfold > General Styling > Quick Css, if it does not work, put into themes/enfold/css/custom.css
#top .av_toggle_section h2.toggler { font-size: 18px !important; }
If you need further assistance please let us know.
Best regards,
VictoriaApril 22, 2020 at 9:53 pm #1206384Thx Victoria, it works great.
April 23, 2020 at 7:27 pm #1206615Hi rvga,
Glad we could help :)
If you need further assistance please let us know.
Best regards,
VictoriaJuly 29, 2021 at 12:10 pm #1313232H all, I had the same idea, to make Toggle title as H2, but if this solution is based on jQuery I don’t think that it is effective for the SEO. Crawlers probably do not execute JS, or I am wrong? Better solution is add this option to the element editor.
July 30, 2021 at 12:02 am #1313348What alb do you mean : the Accordion Slider – there a filter exists to change it : avf_customize_heading_settings
function my_avf_customize_heading_settings( array $args, $context, array $extra_args = array()){ if( $context == 'aviaccordion' ){ $args['heading'] = 'h2'; } return $args; } add_filter( 'avf_customize_heading_settings', 'my_avf_customize_heading_settings', 10, 3 );
but the toggles ( on toggles.php ) there is no such filter.
and I’m afraid that it’s not as easy as changing two places in the code as with some other ALB elements.line: 1048ff ( Enfold 4.8.5)
$output .= "<p data-fake-id='#{$toggle_atts['custom_id']}' class='toggler {$item_titleClass} {$titleClass} {$item_inherit}' {$markup_title} role='tab' tabindex='0' aria-controls='{$toggle_atts['custom_id']}'>"; $output .= $toggle_atts['title']; $output .= '<span class="toggle_icon">'; $output .= '<span class="vert_icon"></span>'; $output .= '<span class="hor_icon"></span>'; $output .= '</span>'; $output .= '</p>';
but you find in that toggles.php also some code correlated to the p-tag:
829ff:'toggle' => ".togglecontainer.{$element_id} p.toggler", 'toggle-current' => ".togglecontainer.{$element_id} p.toggler.activeTitle", 'toggle-hover' => ".togglecontainer.{$element_id} p.toggler:not(.activeTitle):hover", 'toggle-icon' => ".togglecontainer.{$element_id} p.toggler .toggle_icon",
so you can try to change that to f.e.: h2
see here for enfold 4.8.5 : Pastebin
and have your own child-theme toggles.php via well known snippet: https://kriesi.at/documentation/enfold/intro-to-layout-builder/#customizationAugust 1, 2021 at 7:29 am #1313669August 2, 2021 at 11:52 am #1313886Hi guys,
I’ve tried to reproduce the change I made with success in an old site, but unfortunaltely it doesn’t work in that test page:
https://c-serp.fr/accordion-test :((Where the hell am I wrong?
Here is the code I worte in the function.php file of my child-theme:function replace_tags_with_tags(){ ?> <script> (function($) { function replaceElementTag(targetSelector, newTagString) { $(targetSelector).each(function(){ var newElem = $(newTagString, {html: $(this).html()}); $.each(this.attributes, function() { newElem.attr(this.name, this.value); }); $(this).replaceWith(newElem); }); } /* replaceElementTag('h3.aviaccordion-title', '<h2></h2>'); */ replaceElementTag('.toggler', '<h2></h2>'); }(jQuery)); </script> <?php } add_action('wp_footer', 'replace_tags_with_tags');
I can’t help thinking that a simple option that changes ‘p’ into ‘h2’ (or whatever tag) in this ALB accordion element would be a great improvement for noobs like me.
August 2, 2021 at 3:48 pm #1313950@rvga : on developer console it works this way:
maybe you had to refresh all cache and regenerate the merged enfold js files.______
don’t know if the class toggler is used elsewhere in the dom – so be a bit more selective – to avoid replacement at the wrong place.function replace_tags_with_tags(){ ?> <script> (function($) { function replaceElementTag(targetSelector, newTagString) { $(targetSelector).each(function(){ var newElem = $(newTagString, {html: $(this).html()}); $.each(this.attributes, function() { newElem.attr(this.name, this.value); }); $(this).replaceWith(newElem); }); } /* replaceElementTag('h3.aviaccordion-title', '<h2></h2>'); */ replaceElementTag('p.toggler', '<h2></h2>'); }(jQuery)); </script> <?php } add_action('wp_footer', 'replace_tags_with_tags');
August 2, 2021 at 3:54 pm #1313952by the way – i do not test it on life site. If the toggles do not work after replacement !
you had to do that solution here with a child-theme alb element : https://kriesi.at/support/topic/accordion-title-to-h2/#post-1313348
you see there that current and hover etc are correlated to p tag.
just use the edited alb element for new enfold (4.8.6 ) from here: Link
from SEO point of view this is the better solution anyway.August 2, 2021 at 9:12 pm #1313996by the way – if you like to have that on tabs alb element : on tabs.php there is that line 626 (Enfold 4.8.6)
change to :$output .= '<h2 aria-controls="' . $tab_atts['custom_id'] . '-content" role="tab" tabindex="0" data-fake-id="#' . $tab_atts['custom_id'] . '" class="tab ' . $titleClass . '" ' . $markup_title . '>' . $icon.$tab_atts['title'] . "</h2>\n";
Pastebin: Link
-
AuthorPosts
- The topic ‘Accordion Title to h2’ is closed to new replies.