-
AuthorPosts
-
November 3, 2019 at 10:10 am #1153477
Hello. On my site I have defined an Enfold Child Latest News widget, which is set to display several posts from a specific category (screenshot). On one of my pages, using the Avia Page Builder, I have inserted a ‘Widget Area’ element, and have set it to display the widget I created. The front-end of the page then displays a list of posts. But each entry in the list displays a title and a timestamp (screenshot). Is there a non-CSS method to prevent these time stamps from rendering?
I realize I can add this custom CSS to resolve my issue:
.news-time { display: none; }
But I’m curious to know if there is perhaps a PHP solution, which would prevent these timestamps from rendering. Ideally I’m asking if the theme has a custom filter hook I can use to achieve this. If not, how might I approach that? Would the WordPress filter hook
the-title()
be an option? Or is that literally to filter just the title, and not the time stamp?Thanks.
November 6, 2019 at 5:02 pm #1154337Hey FeedXL2019,
The filter in the /enfold/framework/php/class-framework-widgets.php is avia_widget_time, you can try it.
Best regards,
VictoriaNovember 8, 2019 at 12:31 pm #1154957OK thanks for that. I see in
/enfold/framework/php/class-framework-widgets.php
thatavia_widget_time
appears four times. Which of those four applies in my case? I think it’s one of these two:$time_format = apply_filters( ‘avia_widget_time’, get_option(‘date_format’) . ” – ” . get_option(‘time_format’), ‘avia_get_post_list’ );
$time_format = apply_filters( ‘avia_widget_time’, get_option(‘date_format’).” – “.get_option(‘time_format’), ‘avia_newsbox’ );Probably the first?
November 8, 2019 at 1:40 pm #1154994Hi FeedXL2019,
The second line should be used for the news widget.
If you need further assistance please let us know.
Best regards,
VictoriaNovember 8, 2019 at 2:58 pm #1155030Hey!
Please add following code to bottom of Functions.php file in Appearance > Editor
add_filter('avia_widget_time', 'change_avia_date_format', 10, 2); function change_avia_date_format($date, $time_format) { $time_format = get_option('date_format'); return $time_format; }
Regards,
YigitNovember 9, 2019 at 11:30 am #1155193November 11, 2019 at 1:26 am #1155438Hi,
Thank you for the screenshots and the good explanation, I tested @Yigit’s function and was able to adjust it so the date & time will not show, I’m unsure if this has an effect elsewhere so please check.
Try adding this code to the end of your functions.php file in Appearance > Editor:add_filter('avia_widget_time', 'change_avia_date_format', 10, 2); function change_avia_date_format($date, $time_format) { $time_format = get_option(''); return $time_format; }
Best regards,
MikeNovember 11, 2019 at 8:15 am #1155505Hi Mike,
Thanks for that. I’m happy to try that code. But can you tell me what it is *supposed* to do? Specifically, what exactly are $date and $time_format? When I print their values I get:
$date = ‘F j, Y – g:i a’
$format = ‘avia_newsbox’>> I’m unsure if this has an effect elsewhere so please check.
If you can state what exactly the code is supposed to do, it will give me an idea of which other pages might be affected.I tried your code, and what it seems to do is prevent the date from rendering on *all* posts. That’s not exactly what I want. I want the date hidden only if these conditions are met:
1. The page has a post ID of 555.
2. The post does *not* have a category of ‘my_category.’I can probably add these conditional checks to the PHP code myself. But if you can give me more info on $date and $format I would appreciate it.
Thanks.
November 13, 2019 at 12:20 pm #1156361Hi,
Sorry, I didn’t realize that you had a certain criteria that you wanted this to work in, I only saw that in your question you wanted to remove the date and time from your Latest News widget without using css.
Anyways in the function there is no $format there is $date and $time_format
you can read about these here: Formatting Date and Time
you can use an IF statement to trigger the function, please let us know if you want a hand writing an IF statement.Best regards,
MikeNovember 13, 2019 at 12:42 pm #1156374>> Sorry, I didn’t realize that you had a certain criteria that you wanted this to work in, I only saw that in your question you wanted to remove the date and time from your Latest News widget without using css.
Yes I accidentally left out that part about the conditional requirements. But let’s not worry about that–I was able to find a solution in terms of those conditions I specified.
>> Anyways in the function there is no $format there is $date and $time_format
Yes my mistake–I typed
$format
when I meant to type$time_format.
>> you can read about these here: Formatting Date and Time
I had a look at that link. I see that it describes a ‘format string,’ and it looks like the
$date
variable in your function corresponds to a ‘format string.’ But I’m still unclear what the input parameter$time_format
represents in the function. It has a value ofavia_newsbox
when I call the function.Thanks.
November 13, 2019 at 12:55 pm #1156379November 14, 2019 at 10:24 am #1156694So in this case, date_format has a value of
avia_newsbox
?November 14, 2019 at 2:16 pm #1156792Hi,
Sorry, that is not correct date_format is how Date and Time is Formated. Please read: Formatting Date and Time
Here is an example:<span class='date-container minor-meta updated'><?php the_time(get_option('date_format')); ?></span>
Try using Visual Studio Code, it is free, then open the theme folder with it, this will load every file, then you can search “find in files” for “date_format” or anything else, and you will see every instance of it.
Best regards,
MikeNovember 14, 2019 at 2:32 pm #1156798Sorry, maybe I wasn’t clear in what I was trying to describe. Let me backup and re-explain. What I’m saying is that in the PHP function you gave me, if I print the value of the
$time_format
parameter, its value isavia_newsbox
. Is that expected? The page you referenced (Formatting Date and Time) obviously doesn’t reference anything namedavia_newsbox
.Thanks.
November 15, 2019 at 12:24 pm #1157156Hi,
Yes, because theavia_newsbox
is pulling posts, which includes among other things the time and date, thus the filter:
$time_format = apply_filters( 'avia_widget_time', get_option('date_format')." - ".get_option('time_format'), 'avia_newsbox' );
butavia_newsbox
has no baring on$time_format
please see the entire function at\enfold\framework\php\class-framework-widgets.php
this filter occur at line 961Earlier you wrote:
Yes I accidentally left out that part about the conditional requirements. But let’s not worry about that–I was able to find a solution in terms of those conditions I specified.
So this means this is solved?
Best regards,
MikeNovember 16, 2019 at 6:37 am #1157413>> So this means this is solved?
I wouldn’t say this issue is solved. I can say that PHP code I added had the desired result on the front-end. But I’m still trying to understand the code I added, and why it worked. It’s bad practice to add ‘black box’ code that does what you want, without understanding why or how it works.
In the code you gave me, you set
$time_format = get_option( '' );
Why not instead set
$time_format = false;
Doesn’t that accomplish the same thing?
November 19, 2019 at 9:52 am #1158075Hi,
Thank you for the update.
Yes, that should do the same thing — disable the news info in the avia news box or widget. It will not render the news-time container because the $time_format is set to false:
if($time_format) { echo "<span class='news-time'>".get_the_time($time_format)."</span>"; }
Best regards,
IsmaelNovember 19, 2019 at 12:10 pm #1158116OK thanks for confirming. I’ll set the variable to
false
then. We can consider this resolved. -
AuthorPosts
- The topic ‘Latest News widget — how to prevent time stamps from rendering?’ is closed to new replies.