-
AuthorPosts
-
August 23, 2021 at 8:26 pm #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.
August 26, 2021 at 6:05 am #1318376Hey 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,
IsmaelAugust 26, 2021 at 7:46 pm #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.
August 27, 2021 at 11:18 am #1318621Hi,
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,
IsmaelAugust 27, 2021 at 2:04 pm #1318646Thanks, 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!
August 27, 2021 at 2:19 pm #1318649Hey,
It defines the priority. You can read more here – https://developer.wordpress.org/reference/functions/add_action/ :)
Regards,
YigitAugust 27, 2021 at 3:06 pm #1318659create 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/August 27, 2021 at 6:12 pm #1318702Thank you @Guenni007
August 30, 2021 at 5:03 am #1318890 -
AuthorPosts
- You must be logged in to reply to this topic.