Best way to achieve the desired functionality is to use post_meta / custom field.
add_shortcode ('cities', 'show_cities');
function show_cities(){
/*
Create a custom field 'city' to save city name in page editor
*/
$city = get_post_meta( get_the_id(), 'city', true );
return $city;
}
Using an array can also do the work as under:
add_shortcode ('cities', 'show_cities');
function show_cities(){
/*
Create an array using Page_id as index, e.g.
$cities [ 'page_id' ] = "City Name";
*/
$cities [ 7 ] = "New York";
$cities [ 10 ] = "Alabama";
return $cities [ get_the_id() ];
}
Related Posts:
- How to embed page content in a blog post
- Debugging shortcode problems
- How to exclude shortcode from specific page IDs if it’s set to global
- Shortcode produces blank page
- conditional tags- how to use with shortcodes
- Making audio playlist by getting page’s parent’s ID
- Is it possible to check for shortcodes on a page?
- How To Render Shortcode In AJAX Response?
- Shortcode runs when editing page
- How to insert current user ID in a shortcode?
- How to show the view more on my display of pages shortcode
- Pre-populating new Page creation with shortcodes
- How to output different content of page on different places in my template
- custom page or standalone page?
- Get ID of the page where shortcode is included
- How to read a page’s “Shortcodes” from the Template File?
- Check if is on child-page of a particular page
- Create a page without adding a page in the Database
- Restrict admin access to certain pages for certain users
- Require title for pages
- Add a new page to wordpress programmatically
- How do I modify this page template to show subpage excerpts (not post excerpts)?
- List all pages and children in separate ul
- How do I load custom scripts and styles for a page?
- What are the options for running custom css and javascript files on a page?
- How to build a post and comment editing form in a page?
- Wrong Sub-Page Order
- WP won’t save changes in post (any)
- can i create 2 blog ‘feeds’ within one blog
- Password Protected Page Not Displaying Content After Entering Password
- Created pages not showing up in ‘All Pages’ list
- Registering multiple sidebars with data from an array
- I made a custom page but WordPress seems to strip any HTML I put in this page
- Is it possible to have a landing page based on the visitors location?
- Play Video on Homepage Only
- Extra title output with this function wp_list_pages
- Remove number in URL
- Dynamically change page that loads
- Page title not showing up
- How to add Posts to a Page
- Proper way to implement/access a built-in page in my theme
- remove/hide pages from users backend
- Page not found error when adding text `2 = 2 ^ 1` to the page
- Related Links Page with moderated, user suggested link submissions
- If a page does not exist, include a different page?
- How to redirect a page to another?
- I Changed the Menu Order, But the Page Order Didn’t Change on Front Page
- Combining ‘depth’ with ‘include’ in wp_list_pages()
- Page template no longer exists – metaboxes won’t save
- A static page view call every custom page templates
- Wrapping images in tags based on size
- Get the ID of the direct parent page
- External stylesheet per page
- How to add prefix slug in static wordpress page?
- how to avoid the character conversion of WordPress pages?
- access control for assets in a website powered by wordpress
- How to make a page unsearchable in blog search?
- Getting ACF Field in Page – From the Footer
- Rewrite to load homepage for a different url
- logout redirect only from admin page
- multiple post into single page
- redirect index.html inside folder to wordpress page of same name
- Show content if page is a grandchild of top level page
- Does Feedburner send notifications about WordPress pages?
- Ordering Pages and Increasing Navigation
- Static Website No Titles But Still Nav
- Search results to be only posts & children of page ID
- Embedding Password Protected (Private) “Blog Posts” BLOCK that shows Images and Excerpts on Password Protected Page (not the home page)
- On the list of Pages, clicking to Edit a particular page redirects to the list of trash
- My pages are using my Index.php and not my page.php
- WordPress custom pages in a folder
- How to delete the scrollbar in my pages?
- How to make a page as default page for a theme without a plugin?
- Return true if parent page id matches
- Not allow add New Page for role ‘editor’
- My Password Protected Pages Aren’t Working
- How to detect if some page template has been selected
- Why Google map can not show full size in a page?
- Page view displays not properly after update wordpress
- Is it possible to query a category with specified posts?
- What’s the best way to manage sections on a page?
- How do you assign custom template for Posts page (under Front page displays setting)
- Display custom_post_type with current taxonmy of a page
- How to add conent (text) to Add New pages form of admin in WordPress
- Prevent page from displaying
- Adding CSS styles to Admin Area PAGES only (not POSTS or CPT)
- 1st Level Page with No Children
- Loading custom jQuery and HTML in a WordPress page
- Add feed to a custom page
- Directory location of new page
- Grabbing the_content from “about us”
- making a pseudo-static page
- Page specific values in widgets
- Woocommerce – Making product pages child of shop
- link a custom page into menu
- Show different number of posts on second page of category
- Use get_posts() with ‘post’ and ‘page’ queries at the same time?
- appearance of new page
- How can a user login on a wordpress page?
- For some reason my posts are not showing up on my front page [closed]