Community Forums › Forums › Archived Forums › General Discussion › Disabling auto-closing tags in function output?
Tagged: genesis sandbox featured content, widgets
- This topic has 1 reply, 2 voices, and was last updated 9 years, 7 months ago by Nick.
-
AuthorPosts
-
September 11, 2014 at 8:49 pm #124065chrisfromthelcMember
I've got the following two code blocks generating (at least, what I hope to generate) an href link around a block of stuff.
add_action ( 'gsfc_before_post_content', 'gfwa_add_html_markup_inside_loop', 5 ); function gfwa_add_html_markup_inside_loop( $instance ) { if ( $instance['custom_field'] == 'blog-widget' ) { echo '<a href="'.get_permalink().'" class="gfwa-container-div-blog">'; } } add_action ( 'gsfc_after_post_content', 'gfwa_add_html_markup_after_loop_inside', 11 ); function gfwa_add_html_markup_after_loop_inside( $instance ) { if ( $instance['custom_field'] == 'blog-widget' ) { echo '</a>'; } }
However, the href tag gets auto-closed immediately after the first function. I can tell that the second function is working, because any other tags/text generate correctly and in the proper location.
I've tried disabling autop, but that doesn't help here. I think there's possibly something in the Genesis core that is auto-closing the anchor tags.
http://limb.dbsetup.com/September 12, 2014 at 10:11 am #124121NickParticipantIt looks like the closing
</a>
tag is being output correctly, but perhaps not where you expected it to be. If I view source on that page, copy it, and tidy the formatting up with “Reformat Code” in PhpStorm (screenshot: http://d.pr/i/2NmJ ), I can see that the opening<a>
tag gets generated inside thegfwa-container-div
immediately after the linked image, while the closing</a>
tag is generated immediately before the closing</article>
tag for that widget.The link is therefore wrapping an irregular section of your HTML – it wraps the
post-info
andentry-title
blocks, and it wraps the closinggfwa-container-div
tag. But it doesn't wrap the entire contents of thearticle
element (the image and the openinggfwa-container-div
tag). Was that what you intended, or should it be wrapping the entire contents of thearticle
element? If you intended to wrap the entire contents, you could try editing the first action to give it a higher priority so that it executes earlier in an attempt to output your opening<a>
before any other content the plugin attaches to that hook. i.e.:add_action ( 'gsfc_before_post_content', 'gfwa_add_html_markup_inside_loop', 1 );
If that doesn't work out, you might find that you have better control over the output by dropping the Genesis Sandbox Featured Content Widget and using a simple custom page template with a custom loop instead – I think you'd be able to achieve your current layout using a custom page template without too much stress (but feel free to try and ask back here if you still need help).
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.