Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1318035

    I currently use a plugin to convert some PHP into a shortcode that I can them insert into the header, like this:
    <div class = "todays_date">[xyz-ips snippet="todays-date"]</div>

    The PHP is
    echo date('l jS F Y');

    which yields “Monday 23rd August 2021”.

    I am looking to reduce the number of plugins in use for performance reasons.

    Is there a way within the theme to display the day and date via a shortcode, hook, filter or code segment in a custom widget area? I use a child theme and have plenty of different functions in my functions.php file.

    #1318376

    Hey zimbo,

    Thank you for the inquiry.

    Have you tried using hooks such as ava_main_header or ava_inside_main_menu? These hooks are inside the includes > helper-main-menu.php file, which is where most of the header elements such as the main menu, logo and social icons are located.

    Best regards,
    Ismael

    #1318504

    @Ismael – I have not considered hooks and have never created a PHP function from scratch, although I am quite adept at investigating & hacking PHP code modules to get what I want… :-)

    The day and date is written into a custom widget area called ‘header’ that the theme assigns an id of ‘custom_html-7’, and I position it in the header via my child style.css, e.g.

    #header #custom_html-7 {
    	left: 50%;
    	padding-top: 0px;
            etc

    Are there any code examples of using the two hooks you mention that might give me a head start in trying to figure something out? I can’t see anything in Enfold Documentation.

    #1318621

    Hi,

    Thank you for the update.

    You can use one of the hooks in the functions.php as follows.

    add_action("ava_main_header", function() {
       // snippets here
       echo "something";
    }, 10);
    

    .. or:

    
    function ava_add_something_to_the_header() {
       // snippets here
       echo "something";
    }
    add_action("ava_main_header", "ava_add_something_to_the_header", 10); 
    

    Best regards,
    Ismael

    #1318646

    Thanks, I’ll give it a go!

    One further question though – what does the number 10 signify in the add_action (or add_filter)?

    I’ve seen different numbers in some functions (but not others) but never understood what it is, why the number varies or why some functions have one number, some have two, others none. Hope you can shed some light!

    #1318649

    Hey,

    It defines the priority. You can read more here – https://developer.wordpress.org/reference/functions/add_action/ :)

    Regards,
    Yigit

    #1318659

    create your own shortcode f.e. ( sorry – it is mine – so its for german time )
    binding words as friday the 28 had to be escaped
    usage in content : [show-date]

    function show_date_with_shortcode() { 
      date_default_timezone_set('Europe/Berlin');
      setlocale(LC_TIME, 'de_DE.UTF-8');
      $uhrzeit = date_i18n( 'l \d\e\n ' . get_option( 'date_format' ) . ' ' . get_option( 'time_format' ). ' \U\h\r'  );
      return $uhrzeit ;
    }
    add_shortcode( 'show-date', 'show_date_with_shortcode' );

    or in this way:

    function datum_shortcode() {
      $year = date_i18n('Y');
      $day = date_i18n('d');
      $month = date_i18n('F');
      $weekday = date_i18n('l');
      $datecolor = date_i18n('l') == 'Sonntag' ? 'red': 'gray' ;
    
      $datum = '<div id="kalenderblatt"><div class="monat-jahr"><span class="monat">'.$month.'</span><span class="jahr">' .$year.'</span></div><div class="tag ' .$datecolor.'">'.$day.'</div><div class="wochentag">'.$weekday.'</div></div>';
      return $datum;
    }
    add_shortcode('show-date', 'datum_shortcode');
    

    to have with a little css:
    https://basis.webers-testseite.de/calendar-sheet/

    #1318702

    Thank you @Guenni007

    #1318890

    Hi,

    Thanks for helping out @guenni007 :-)

    Best regards,
    Rikard

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.