How to get URL param to shortcode?

I can't find solution for this ...URL: www.foosome_page?name=JohnPage content:Hi [Name]!Worpress still redirects

I can't find solution for this ...

URL: www.foo/some_page/?name=John

Page content:

Hi [Name]!

Worpress still redirects back to www.foo/some_page/

I tried everything ...

I need something like the following in functions.php

function name_shortcode() {
    return $_GET['name'];
}
add_shortcode( 'Name', 'name_shortcode' );

And on another page: Click here www.foo/some-page/?name=John

I can't find solution for this ...

URL: www.foo/some_page/?name=John

Page content:

Hi [Name]!

Worpress still redirects back to www.foo/some_page/

I tried everything ...

I need something like the following in functions.php

function name_shortcode() {
    return $_GET['name'];
}
add_shortcode( 'Name', 'name_shortcode' );

And on another page: Click here www.foo/some-page/?name=John

Share Improve this question edited Jul 24, 2014 at 0:18 Johannes P. 11.1k3 gold badges42 silver badges53 bronze badges asked Jul 23, 2014 at 20:00 Karel FundaKarel Funda 931 gold badge1 silver badge3 bronze badges 4
  • please show the code for "some_page". It's impossible to help you without seeing any code. And what shortcode are you using? – gdaniel Commented Jul 23, 2014 at 20:24
  • I tried everything ... (I deleted code) I need some like in functions.php function name_shortcode() { return (I don't know) $_GET['name']; } add_shortcode('Name', 'name_shortcode'); another page: Click here http://www.foo/some-page/?name=John – Karel Funda Commented Jul 23, 2014 at 21:00
  • You can edit your question, rather than adding information as a comment. – Johannes P. Commented Jul 24, 2014 at 0:18
  • That being said, when dies WordPress redirect to www.foo/some_page/? – Johannes P. Commented Jul 24, 2014 at 0:19
Add a comment  | 

2 Answers 2

Reset to default 7

If I understand your question correctly, you want to be able to get the parameter from the url, add it to the shortcode so you can add the parameter to the content.

See if this works:

add_shortcode('name', 'get_name');

function get_name() {

   return $_GET['name'];

}

In the wordpress backend editor you would have something like:

Hello [name], Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.

We built a plugin that will do this for you https://wordpress/plugins/display-url-params/ - It uses a simple shortcode to get URL parameters from the Query String and display them as dynamic content on pages and posts.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745151133a4613874.html

相关推荐

  • How to get URL param to shortcode?

    I can't find solution for this ...URL: www.foosome_page?name=JohnPage content:Hi [Name]!Worpress still redirects

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信