After 3 or 4 hours of searching the web for a solution, I abandoned it and hopefully you can help me?

  1. I added a sub-headline as a custom field (subheadlineclass). That works pretty. I can save, edit and open it in WordPress' post-editor.

  2. There is a shortcode in this custom field to generate this sub-title dynamically. (I use PHP Code for posts to do so.)

3.1. Also, it's no problem to call this custom field (as a executed shortcode) in my template with:

if (!empty(get_post_meta(get_the_ID(), "subheadlineclass", true))) {
$subheadline = get_post_meta(get_the_ID(), "subheadlineclass", true);
$subheadline = do_shortcode(subheadline);

3.2. This lines are placed in the index.php (inside the loop). After this, I can use the variable $subheadline to place the sub-headline, wherever I want (for example below the title).

3.3. Of course you need to add this to the functions.php:

add_filter( "the_content", 'do_shortcode');
  1. Anyway, now to the problem: I outsourced many snippets from the functions.php to a "plugin" (actually it doesn't matter, if it's the functions.php or placed in a plugin to solve this issue). At this place I cannot use this snippet any longer. The string is empty.

BUT this var_dump tells me, the shortcode isn't just executed:

$shortcode = get_post_meta(get_the_ID(),'subheadlineclass',true);


string(40) "[php snippet=1 param="subheadline=1"]"

Soooo I cann call the variable of the custom field, but do_shortcode (like in 3.1.) doesn't work. But why? And how can this problem be solved? Thanks!

  • Can you expand on "doesn't work" from the last paragraph? Have you tried echoing $shortcode, e.g. $shortcode = get_post_meta(get_the_ID(),'subheadlineclass',true); echo $shortcode; – Dave Romsey Apr 6 '17 at 18:51
  • Sorry, for didn't myself clear. The snippet in 3.1. works not like in 4., when I put it to the functions.php. Your example: echo $shortcode; leads to an empty string (I mentioned that at "Output"). Nevertheless, at THIS position, there is just the shortcode as plaintext, not the executed shortcode, which you can do via do_shortcode. – Sebastian Apr 6 '17 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.