Tagged: 

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #695597

    Not rendering – just displaying the shortcode in the page. What is wrong?

    In my child theme > functions.php

    function my_shortcode_function(){
    	$str = "this is my text.";
    	return $str;
    }
    add_filter( 'show-my-text', 'my_shortcode_function' );

    In a text block of a page i put:
    [show-my-text]

    The page displays: [show-my-text]

    What could cause this?

    • This topic was modified 8 years, 2 months ago by galpinr.
    #695625

    Found the problem I think. The code in functions.php to add the shortcode needs to be:

    add_shortcode( 'show-my-text', 'my_shortcode_function' );`

    NOT what I had:

    add_filter( 'show-my-text', 'my_shortcode_function' );`

    Don’t know how I ended up with add_filter.

    #695628

    Hi!

    Yes, that is the issue.
    For more information, please see – https://codex.wordpress.org/Shortcode_API

    Best regards,
    Yigit

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.