Viewing 18 posts - 1 through 18 (of 18 total)
  • Author
    Posts
  • #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.

    #1154337

    Hey FeedXL2019,

    The filter in the /enfold/framework/php/class-framework-widgets.php is avia_widget_time, you can try it.

    Best regards,
    Victoria

    #1154957

    OK thanks for that. I see in /enfold/framework/php/class-framework-widgets.php that avia_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?

    #1154994

    Hi FeedXL2019,

    The second line should be used for the news widget.

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

    #1155030

    Hey!

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

    #1155193

    @Victoria OK thanks for confirming.


    @Yigit
    Thanks for that. But what exactly will that code do? I added it, but there was no noticeable change to the front-end.

    #1155438

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

    #1155505

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

    #1156361

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

    #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 of avia_newsbox when I call the function.

    Thanks.

    #1156379

    Hi,
    $time_format is get date_format from WordPress, that’s all.

    Best regards,
    Mike

    #1156694

    So in this case, date_format has a value of avia_newsbox?

    #1156792

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

    #1156798

    Sorry, 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 is avia_newsbox. Is that expected? The page you referenced (Formatting Date and Time) obviously doesn’t reference anything named avia_newsbox.

    Thanks.

    #1157156

    Hi,
    Yes, because the avia_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' );
    but avia_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 961

    Earlier 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,
    Mike

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

    #1158075

    Hi,

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

    #1158116

    OK thanks for confirming. I’ll set the variable to false then. We can consider this resolved.

Viewing 18 posts - 1 through 18 (of 18 total)
  • The topic ‘Latest News widget — how to prevent time stamps from rendering?’ is closed to new replies.