Skip to content
Advertisement

Why is WordPress not recognising the function I created?

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:

JavaScript

I have written the following function in functioins.php:

JavaScript

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:

JavaScript

But it just published “hov(arg1,arg2)” as a literal string. Any ideas what I am doing wrong? Thanks in advance.

Advertisement

Answer

If you’re trying to type hov('foo', 'bar'); into your HTML then it will output that as text.

To call a PHP function from inside your template you need the opening and closing PHP tags.

So in your templates, to call this function you would use the following code.

JavaScript

If you’re trying to call for a shortcode then you need to use echo do_shortcode(['...']);

JavaScript

Revised Answer

To run a PHP function by calling it in the post editor you need to create a shortcode

Shortcodes are created by using the WordPress function add_shortcode See: https://developer.wordpress.org/plugins/shortcodes/

JavaScript

Example usage

[hov y="foo" x="bar"] Where x and y are passed as items inside of $args

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement