Viewing 30 posts - 1 through 30 (of 34 total)
  • Author
    Posts
  • #1001137

    Dear support,
    is there a way to change the accordion title to <h2>? Because of SEO optimization.
    Thanks for any help

    #1001174

    put 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');
    #1001176

    PS
    this line

    replaceElementTag('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 replacements

    #1001191

    Hey 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.de

    #1001205

    you 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.

    #1001206

    ok 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!

    #1001209

    Thanks, 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

    #1001213

    Ooops, i was too fast :-)
    If you scroll down to the element with the green gradient background, section-id is “seotext”

    #1001214

    if 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.

    #1001217

    Yes 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!

    #1001224

    Hi dondela,

    Glad Guenni007 helped you to get it working.

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #1001272

    Yes – it is hard to make a statement only about the simulation in the developer tools.
    So i’m glad that it works for you now

    #1001487

    Hi,

    Thanks for helping out @guenni007 :-)

    Best regards,
    Rikard

    #1203345

    Hello,
    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-questions

    Does anyone see why it doesn’t work?

    • This reply was modified 4 years, 8 months ago by rvga.
    #1203626

    Hi 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,
    Victoria

    #1205439
    This reply has been marked as private.
    #1205747

    Hi,

    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,
    Ismael

    #1205816

    It works perfectly thanks to you Ismael.

    And what would be its css code to change the H2 font-size please ?

    #1205924

    Hi,

    h2{
    font-size:20px;
    }

    Adjust the size to what you need.

    Best regards,
    Jordan Shannon

    #1206089

    Sorry 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?

    #1206346

    Hi 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,
    Victoria

    #1206384

    Thx Victoria, it works great.

    #1206615

    Hi rvga,

    Glad we could help :)

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #1313232

    H 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.

    #1313348

    What 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/#customization

    #1313669

    Hi,

    Thanks for helping out @guenni007 :-)

    Best regards,
    Rikard

    #1313886

    Hi 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.

    #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');
    #1313952

    by 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.

    #1313996

    by 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

Viewing 30 posts - 1 through 30 (of 34 total)
  • The topic ‘Accordion Title to h2’ is closed to new replies.