Wordpress functions.php shortcode is not working

admin2025-06-04  2

Closed. This question is off-topic. It is not currently accepting answers.

Questions that are too localized (such as syntax errors, code with restricted access, hacked sites, hosting or support issues) are not in scope. See how do I ask a good question?

Closed 6 years ago.

Improve this question

I have new WordPress (5.0.2) install with the code added to the end of functions.php file:

function testsc(){
    return "It is working!";
}

function testsc2(){
    return "It is working!";
}

add_shortcode('testshortcode', testsc);
add_shortcode('testshortcode2', 'testsc2');

With Debug Objects plugin installed i can see that short codes are added:

Shortcode: testshortcode Function: testsc
Shortcode: testshortcode2 Function: testsc2

But when i put testshortcode or testshortcode2 in a page it is treated as text.

I use default theme: Twenty Sixteen.

Closed. This question is off-topic. It is not currently accepting answers.

Questions that are too localized (such as syntax errors, code with restricted access, hacked sites, hosting or support issues) are not in scope. See how do I ask a good question?

Closed 6 years ago.

Improve this question

I have new WordPress (5.0.2) install with the code added to the end of functions.php file:

function testsc(){
    return "It is working!";
}

function testsc2(){
    return "It is working!";
}

add_shortcode('testshortcode', testsc);
add_shortcode('testshortcode2', 'testsc2');

With Debug Objects plugin installed i can see that short codes are added:

Shortcode: testshortcode Function: testsc
Shortcode: testshortcode2 Function: testsc2

But when i put testshortcode or testshortcode2 in a page it is treated as text.

I use default theme: Twenty Sixteen.

Share Improve this question edited Jan 4, 2019 at 16:36 hal asked Jan 4, 2019 at 15:04 halhal 1351 silver badge7 bronze badges 8
  • Try 'testSC' instead of testSC (unquoted), when in the add_shortcode() call. – Sally CJ Commented Jan 4, 2019 at 15:29
  • Still not working – hal Commented Jan 4, 2019 at 15:34
  • Did you try with the Shortcode or Code block in the new editor? And you're referring to the theme's functions.php file, right? Try disabling all or certain plugins on your site. – Sally CJ Commented Jan 4, 2019 at 15:39
  • I used Shortcode block from new editor. Other blocks generate error during saving. Yes. I am refering to the theme's functions.php. I don't have active any plugin besides Debug Objects. – hal Commented Jan 4, 2019 at 15:51
  • Try using lowercases.. testshortcode. – Sally CJ Commented Jan 4, 2019 at 15:56
 |  Show 3 more comments

1 Answer 1

Reset to default 1

Finally it worked.

To ensure that, all following conditions must be met:

  • declarations must be in lowercase
  • do not use echo but return the content
  • square brackets are required even in the shortcode block.
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749044538a315882.html

最新回复(0)