-
AuthorPosts
-
May 5, 2021 at 4:46 pm #1298647
Hi,
Im using the blog element grid display. Im trying to move the date so its under the caption/excerpt. I have found a couple post about moving things around in there but I cant seem to get it working.
Here is what im looking for.
Image
Exerpt
DateHere is the code im using.
function ava_move_meta_after_title(){ ?> <script> jQuery('.slide-content').each(function(i) { var metaInfo = jQuery(this).find('.slide-meta'); var postTitle = jQuery(this).find('.entry-content-header'); jQuery(metaInfo).insertAfter(postTitle); }); </script> <?php } add_action('wp_footer', 'ava_move_meta_after_title');
When adding that in I get a JS error
Uncaught TypeError: $ is not a function
at (index):335
(anonymous) @ (index):335Can you help me out here?
Thanks
-DanMay 5, 2021 at 4:55 pm #1298649can you post a link to the page it concerns – or if you don’t want to make it public – is there a demo page that shows the issue?
f.e.: https://kriesi.at/themes/enfold-2017/blog/blog-default/May 5, 2021 at 4:58 pm #1298651Here is the link.
Is that using the blog element within the page builder or is that an archive page?
That is exactly what im looking for.
Thanks
-DanMay 5, 2021 at 5:13 pm #1298660i prefere to write the whole script a $ instead of jQuery – makes some things easier to understand.
try:
function ava_move_meta_after_title(){ ?> <script> (function($){ $('.slide-entry').each(function() { var metaInfo = $(this).find('.slide-meta'); var postTitle = $(this).find('.entry-content-header'); metaInfo.insertBefore($(postTitle)); }); })(jQuery); </script> <?php } add_action('wp_footer', 'ava_move_meta_after_title');
May 5, 2021 at 5:17 pm #1298661definitly this will work too:
function ava_move_meta_after_title(){ ?> <script> (function($){ $('.slide-entry').each(function() { var metaInfo = $(this).find('.slide-meta'); var postTitle = $(this).find('.entry-content-header'); postTitle.insertAfter($(metaInfo)); }); })(jQuery); </script> <?php } add_action('wp_footer', 'ava_move_meta_after_title');
May 6, 2021 at 3:39 pm #1298813Hi,
Thanks for the help on this. Its still not working. I still get a jquery not defined error in the console.
I edited the code also as I need the date to show up AFTER the excerpt. I think that code was trying to put it after the title. Here is what im using now but still not working.
function ava_move_meta_after_title(){ ?> <script> (function($){ $('.slide-entry').each(function() { var metaInfo = $(this).find('.slide-meta'); var postTitle = $(this).find('.slide-entry-excerpt'); metaInfo.insertAfter($(postTitle)); }); })(jQuery); </script> <?php } add_action('wp_footer', 'ava_move_meta_after_title');
if i remove the (jQuery) part at the end I do not get that console error but still does not work.
Thanks
- This reply was modified 3 years, 6 months ago by acscreativenew.
May 7, 2021 at 1:06 pm #1298941you have choosen to load the jQuery script in the footer ( Enfold Options – Performance – “Load jQuery in your footer” )
so when i inspect your DOM i can see that my script is loaded before the jquery script is loaded !
so the jQuery in my script refers to something that is not yet there.
_________You can do now: change the fact that jQuery is loaded in the footer
or try to load the custom script latertry first:
function ava_move_meta_after_title(){ ?> <script> (function($){ $('.slide-entry').each(function() { var metaInfo = $(this).find('.slide-meta'); var postTitle = $(this).find('.entry-content-header'); postTitle.insertAfter($(metaInfo)); }); })(jQuery); </script> <?php } add_action('wp_footer', 'ava_move_meta_after_title', 999 );
the 999 is called priority – you can see here some info: https://developer.wordpress.org/reference/functions/add_action/
_____________________
yes — your code then will be ok if you like to bring the date under the excerpt. – but use a priority
- This reply was modified 3 years, 6 months ago by Guenni007.
May 8, 2021 at 7:47 am #1299074May 10, 2021 at 3:47 pm #1299396This worked! Thanks so much for helping out here.
Thanks
-DanMay 10, 2021 at 4:19 pm #1299412Hi Dan,
We’re glad to hear that :)
Thanks for using Enfold and have a great day!Best regards,
Nikko -
AuthorPosts
- The topic ‘Blog Element – Move Date Under Excerpt’ is closed to new replies.