I am trying to create a function with two variables. One variable is the text I want to hover over, the other variable is the text I want displayed when I hover over the first text mentioned. I'm using the following shortcode from Shortcodes Ultimate to create this function:
[su_tooltip style="yellow" position="top" shadow="no" rounded="no" size="default" title="" content="Tooltip text" behavior="hover" close="no" class=""]Hover me to open tooltip[/su_tooltip]
I have written the following function in functioins.php:
function hov($x, $y)
{
echo "[su_tooltip style= \"yellow\"
position=\"top\"
shadow=\"no\"
rounded=\"no\"
size=\"default\"
title=\"\"
content =strval($y)
behavior=\"hover\"
close=\"no\"
class=\"\"]$x'[/su_tooltip)]'";
}
I added the backslash so the code ignores the quotes. I saved this function. I tried running this function in a text editor page as follows:
hov(arg1,arg2)
But it just published "hov(arg1,arg2)" as a literal string. Any ideas what I am doing wrong? Thanks in advance.
If you're trying to type
hov('foo', 'bar');
into yourHTML
then it will output that as text.To call a
PHP
function from inside your template you need the opening and closingPHP
tags.So in your templates, to call this function you would use the following code.
If you're trying to call for a
shortcode
then you need to useecho do_shortcode(['...']);
Revised Answer
To run a
PHP
function by calling it in the post editor you need to create ashortcode
Shortcodes are created by using the WordPress function
add_shortcode
See: https://developer.wordpress.org/plugins/shortcodes/Example usage
[hov y="foo" x="bar"]
Wherex
andy
are passed as items inside of$args