最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to get URL param to shortcode?

programmeradmin0浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论