You can simply use the get_the_title() function to get the current post’s title in your shortcode. If you want it to work only on pages, you can combine it with is_page():
function shortcode($atts) {
extract(
shortcode_atts(
array(
'name' => get_the_title(),
) ,
$atts)
);
// Rest of your code
}
add_shortcode('short_code', 'short_code');
You can use a PHP shorthand conditional as follows:
'name' => ( is_page() ) ? get_the_title() : 'Your else goes here' ;
Related Posts:
- Implementing a CrunchBase.com Clone using WordPress?
- wp.media.view.ImageDetails – Save settings as HTML5 data-* attributes for image
- How to share category taxonomy with custom post type (The Event Calendar plugin)
- Are drop-in plugins a product of design
- How can I make it so the Add New Post page has Visibility set to Private by default?
- Use a plugin to handle custom post types?
- Override plugin localization
- How wordpress detects a plugin update
- Right approach for plugin output styling/template
- When do I need to use esc_attr when using WordPress internal functions
- Absolute Path (ABSPATH) in WordPress is not working
- Create Proper WordPress Ajax Request in JavaScript, NOT jQuery
- How to select featured images for 1500 posts?
- Store post in raw markdown format, no html?
- Translating wordpress plugin
- Extending WP’s upload/insert media functionality
- Strip HTML comments from plugins in header/footer
- How to get the permalink of a page when loading my plugin
- How to expire all wordpress user passwords instantly?
- locate_template with multiple categories?
- WordPress and WebRTC?
- Hardcode a Plugin into theme
- How create a role with admin capability less 1 or 2?
- Ajax gives 400 error
- Change words on ‘Log in’ and ‘Register’ buttons on Woocommerce
- Override WP Class Private Function
- How to Include a Loop Template File in a Plugin
- How to show Categories and Sub-categories using WooCommerce
- React JSX in WordPress Plugin Development
- How to add a default value to get_option if it’s used as a variable?
- My plugin wants to update another plugin
- How to show Recent Page instead of Post?
- How do I pass a post ID to the page URL?
- Allow HTML in Excerpts in Elementor
- Need to change url paramenter of share product pintrest [closed]
- Calculate price and display on woocommerce product single page under price (simple price, variable price) [closed]
- Classified ad website : which solutions to use? [closed]
- wp_redirect() Error in Custom Plugin
- Bootstrap and Custom CSS in custom plugin are being overwritten by theme
- Loading a purchased jquery plugin in a wordpress theme
- Fullscreen Video/GIF Intro
- Multisite for Multisite?
- Basic function call on init failing
- Display a consistent Google Plus icon on ALL pages of my site
- breadcrumb need to show all pages and subpages
- Is it possible not to load theme on a specific page in wordpress?
- How to change shortcode’s default theme?
- How to accept images at multiple sizes and aspect ratios and display as standardized image size / ratio?
- Mutliple users editing single document in wordspress
- Plugin: connect to external database without showing password
- wp_insert_post() inside save_post(): force WP to not update global post object?
- Woocommerce: Set thumbnail detail (clipping area)
- Filtered content appears in the excerpt
- My plugin does not install correctly if a previous version is still installed
- How to disable Wp-PageNavi at the top of the page
- Why aren’t my Follow Me links working?
- WordPress ping spam issue with Ping services?
- Hook from plugin doesn’t fire up from external PHP script
- Custom User Registration Form not showing
- Drag and drop widget always inserts image
- SMTP emails not picking up the correct From name and From email
- What database state changes happen after a post is manually “updated” with no changes?
- Display posts by alphabetical order
- wp_insert_post not inserting post from XML
- custom fields not displaying on wordpress site
- Overriding a function in a WordPress plugin
- after logout session not destroy from server/website side
- How To Toggle User_Meta in frontend in a form using PHP
- How to update a database entry with a wordpress plugin?
- Change Woo Custom Endpoint Titles from a Plugin
- Is there a way to display multiple authors on a post?
- White blank screen while adding or editing pages in wordpress
- How can I store user preferences in WordPress and retreive them later?
- Plugin debugging with errors in activation routine
- one admin for 2 wordpress websites
- DB Sync Media Files extension [closed]
- Disqus comment system – change comments number before “load more” button
- Authenticating custom field on login
- Disable default posts (Posts,Pages,Comments and Media) in wp-admin
- How to get rid of error message of custom metabox in dashboard when moving out of edit page?
- W3 Total Cache Can’t Really Detect Things
- Is it right way to create shortcode?
- Storing values in Post Meta vs new tables
- Determine if get_the_image has image on Get the image Plugin
- Translate Woosidebars plugin strings
- How to add different CSS for galleries
- How do I add php to all links automatically?
- Why my site loads too Slow? [closed]
- Plugin Links to page not working
- How should I force WordPress to give proper name for the uploading images?
- plugin how to find code and edit it in a template file?
- how do I solve Installation failed: There has been a critical error on your website
- Can i have limit posts on a specific category and automatically remove older ones?
- manage_{taxonomy}_custom_column not working
- Why wordpress site is hitting itself
- I want create woocommerec match products columns
- How to be Variables and options must be escaped when echo’d?
- How to restrict the unauthorized software download
- Rank Math Seo register custom xml url
- How to force login on wordpress error