Is it possible to call a function from functions.php in custom page or blog post?
I put simple function in functions.php:
function testTest()
{
echo "Test";
}
And called it from the page:
<?php testTest();?>
-ckn-:
I trådens svar gives anvisning på hvordan man kan kalde en funktion. F.eks. opsætte en shortcode til at kalde den.
Det kan være værd at lege lidt med i sandkassen. F.eks. til Copyright note.
Jeg har i mine Shaarli henvisninger til:
Elegant WordPress Solution for Dynamic Copyright Date
32 Extremely Useful Tricks for the WordPress Functions File
Været optaget af hvordan man kan anvende en funktion til at indsætte dynamisk ©️ information.
Med FSE benyttes ikke længere footer.php til footer information. Men der kan stadig benyttes php-script.
Indsæt funktionen i temaets functions.php :
/* ===========
-ckn- Her laver vi dynamisk copyrigt på vores side.
Indsæt for eksempel i footer.php et kald til funktionen.
<?php echo ckn_copyright(); ?>
========*/
function ckn_copyright() {
global $wpdb;
$copyright_dates = $wpdb->get_results("
SELECT
YEAR(min(post_date_gmt)) AS firstdate,
YEAR(max(post_date_gmt)) AS lastdate
FROM
$wpdb->posts
WHERE
post_status = 'publish'
");
$output = '';
if($copyright_dates) {
$copyright = "© " . $copyright_dates[0]->firstdate;
if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
$copyright .= '-' . $copyright_dates[0]->lastdate;
}
$output = $copyright;
}
return $output;
}
Herefter kan funktionen kaldes hvorsomhelst med :
<?php echo ckn_copyright(); ?>
For eksempel i sidefods template.
XAMPP (the local webserver for Windows) do not come with Imagick installed.
If you want your PHP code to be able to use ImageMagick to edit images on a PC, you must download two pieces of software:
ImageMagick: an image editing program
Imagick: a PHP extension that allows PHP code to control the ImageMagick program.
To allow WordPress to operate optimally and to maximise compatibility with many popular plugins and themes it is highly recommended to install the PHP extension Imagick.
Here's a how-to for installation under XAMP
Undrer du dig over, hvad du kan gøre med WordPress' functions-fil? Alle WordPress-temaer kommer med en functions.php-fil. Denne fil fungerer som et plugin, der giver temaudviklere og almindelige brugere mulighed for nemt at tilføje brugerdefineret kode i WordPress.
Her er en række funktioner man kan skrive ind i sit tema, for at få nye funktionaliteter...
Her er en elegant metode til at få opdateret © information.
Se eventuelt også den version af scriptet, der er brugt under #6 i denne :
https://www.wpbeginner.com/wp-tutorials/25-extremely-useful-tricks-for-the-wordpress-functions-file/