Shortcode To Display Post Custom Field Value Inside Excerpt

I want to create a shortcode that pulls value from a custom field of a post and returns that value inside excerpt.

I already have a function for the custom value:

function geo_name_function( $atts ) {

    $atts = shortcode_atts( array(
        'post_id' => get_the_ID(),
    ), $atts, 'geo_name' );

    return get_post_meta( $atts('post_id'), 'field_name', true );

add_shortcode('geo_name', 'geo_name_function');

And filter for the title:

add_filter( 'the_title', function( $geo_name_function ) {
    return do_shortcode( $geo_name_function );

add_filter( 'the_title', 'se385007_title_filter', 20, 2 );
function se385007_title_filter( $title, $post_id ) 
    $new_title = str_replace( "(geo_name)", "(geo_name post_id=$post_id)", $title );
    return do_shortcode( $new_title );

I thought that by adding the Excerpt filter:

add_filter( 'oceanwp_excerpt', 'do_shortcode');

It will fix it but it did not.

I tried adding few other filters but just ended up breaking WordPress ).

At the moment if Custom Value is Ice Cream. If my excerpt is Favorite (geo_name) it only returns Favorite.

Please assist!

Add Shortcode Inside Excerpt – WordPress Development Stack Exchange

I have the following function:

function word_function(){

add_shortcode('word_place', 'word_function');

add_filter('get_the_excerpt', 'do_shortcode');

It places the word “PLACEHOLDER” anywhere I put the (word_place) shortcode.

I want to put the shortcode inside excerpts so that:

“Place Excerpt (word_place) Here”

Would look like:

“Place Excerpt PLACEHOLDER Here”

When the post/page is published.

At the moment it works for a blog page, however when it comes to category and tag pages it still looks like:

“Place Excerpt (word_place) Here”

I’ve had a similar issue with widgets and I’ve used filters to correct the problem.

I’ve found the following filters for excerpts:

add_filter('get_the_excerpt', 'do_shortcode');
add_filter( 'the_excerpt', 'shortcode_unautop');
add_filter( 'the_excerpt', 'do_shortcode');
echo do_shortcode(get_the_excerpt());
echo do_shortcode(the_excerpt());


 * Template for displaying archive layout for easy digital downloads
 * @package OceanWP WordPress theme

global $post;

do_action( 'ocean_before_archive_download_item' );


<div <?php post_class(); ?>>

    <div class="edd_download_inner">


    // Get elements.
    $elements = oceanwp_edd_archive_elements_positioning();

    // Loop through elements.
    foreach ( $elements as $element ) {

        // Image.
        if ( 'image' === $element ) {
            do_action( 'ocean_before_archive_download_image' );

            edd_get_template_part( 'shortcode', 'content-image' );

            do_action( 'ocean_after_archive_download_image' );

        // Category.
        if ( 'category' === $element ) {

            do_action( 'ocean_before_archive_download_categories' );

            echo '<div class="edd_download_categories">';

            echo oceanwp_edd_terms_list( 'download_category' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

            echo '</div>';

            do_action( 'ocean_after_archive_download_categories' );

        // Title.
        if ( 'title' === $element ) {

            do_action( 'ocean_before_archive_download_title' );

            edd_get_template_part( 'shortcode', 'content-title' );

            do_action( 'ocean_after_archive_download_title' );


        // Price.
        if ( 'price' === $element ) {

            do_action( 'ocean_before_archive_download_price' );

            edd_get_template_part( 'shortcode', 'content-price' );

            do_action( 'ocean_before_archive_download_price' );


        // Description.
        if ( 'description' === $element ) {

            do_action( 'ocean_before_archive_download_description' );

            edd_get_template_part( 'shortcode', 'content-excerpt' );

            do_action( 'ocean_after_archive_download_description' );


        // Add to cart button.
        if ( 'button' === $element ) {

            do_action( 'ocean_before_archive_download_add_to_cart' );

            echo oceanwp_edd_add_to_cart_link(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

            do_action( 'ocean_after_archive_download_add_to_cart' );





do_action( 'ocean_after_archive_download_item' );


 * The main template file.
 * This is the most generic template file in a WordPress theme and one of the
 * two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * For example, it puts together the home page when no home.php file exists.
 * Learn more:
 * @package OceanWP WordPress theme

get_header(); ?>

    <?php do_action( 'ocean_before_content_wrap' ); ?>

    <div id="content-wrap" class="container clr">

        <?php do_action( 'ocean_before_primary' ); ?>

        <div id="primary" class="content-area clr">

            <?php do_action( 'ocean_before_content' ); ?>

            <div id="content" class="site-content clr">

                <?php do_action( 'ocean_before_content_inner' ); ?>

                // Check if posts exist.
                if ( have_posts() ) :

                    // Elementor `archive` location.
                    if ( ! function_exists( 'elementor_theme_do_location' ) || ! elementor_theme_do_location( 'archive' ) ) {

                        // Add Support For EDD Archive Pages.
                        if ( is_post_type_archive( 'download' ) || is_tax( array( 'download_category', 'download_tag' ) ) ) {

                            do_action( 'ocean_before_archive_download' );

                            <div class="oceanwp-row <?php echo esc_attr( oceanwp_edd_loop_classes() ); ?>">
                                // Archive Post Count for clearing float.
                                $oceanwp_count = 0;
                                while ( have_posts() ) :
                                    get_template_part( 'partials/edd/archive' );
                                    if ( oceanwp_edd_entry_columns() === $oceanwp_count ) {
                                        $oceanwp_count = 0;

                            do_action( 'ocean_after_archive_download' );
                        } else {
                        <div id="blog-entries" class="<?php oceanwp_blog_wrap_classes(); ?>">

                            // Define counter for clearing floats.
                            $oceanwp_count = 0;

                            // Loop through posts.
                            while ( have_posts() ) :

                                // Add to counter.

                                // Get post entry content.
                                get_template_part( 'partials/entry/layout', get_post_type() );

                                // Reset counter to clear floats.
                                if ( oceanwp_blog_entry_columns() === $oceanwp_count ) {
                                    $oceanwp_count = 0;

                            <?php endwhile; ?>

                        </div><!-- #blog-entries -->

                            // Display post pagination.

                    // No posts found.
                    else :

                        // Display no post found notice.
                        get_template_part( 'partials/none' );

                    <?php endif; ?>

                <?php do_action( 'ocean_after_content_inner' ); ?>

            </div><!-- #content -->

            <?php do_action( 'ocean_after_content' ); ?>

        </div><!-- #primary -->

        <?php do_action( 'ocean_after_primary' ); ?>

    </div><!-- #content-wrap -->

    <?php do_action( 'ocean_after_content_wrap' ); ?>

<?php get_footer(); ?>

However, none of them work for me.

Any assistance is appreciated.

plugins – Shortcode use creates a scroll error/ jump to top of page?

I’m using “Coin Widgets” plugin in WordPress. I’m using it in the sidebar widget area. When using the following shortcode:

[vcw-price-label id="bitcoin" color="white" currency="USD" url="/" target="_blank" fullwidth="no" show_logo="yes"]

The page jumps to the top when I scroll to the end/bottom of the page. I’ve tried changing the variables of the shortcode but I’m still getting the scroll error.

Is there a fix for this?

woocommerce offtopic – Switch to user link shortcode

I am using the User Switching plugin in order to allow sales agents to place an order on behalf of a customer.

I have a page called My Customers which uses toolset to return a list of their customers. I’d like to add a link that allows them to switch to each user on this page.

I have tried adding the following code to functions.php and receive a critical error on the page, code is directly from the developer.

// Add Shortcode
function userswitch_shortcode() {

    if ( method_exists( 'user_switching', 'maybe_switch_url' ) ) {
        $url = user_switching::maybe_switch_url( $target_user );
        if ( $url ) {
                '<a href="%1$s">Switch to %2$s</a>',
                esc_url( $url ),
                esc_html( $target_user->display_name )

add_shortcode( 'userswitch', 'userswitch_shortcode' );

php – How can I get content inside one shortcode to another shortcode?

I have 2 shortcodes, (ref) and (references).
I need to get the content inside the (ref) shortcode and output it when the (references) shortcode is called.

For an example;

  • INPUT –
    This is some content in the webpage outside the shortcode. (ref) This is some content inside the shortcode “ref”. (/ref)
    This is some other content.
    References : (references)

    This is some content in the webpage outside the shortcode.
    This is some other content.
    References : This is some content inside the shortcode “ref”.

Here’s the code that I’ve tried using, but I can’t get it to display the content.

function ref_shortcode( $atts , $content = null ){
    static $i=1;
    $return_value = '<a href="https://localhost/reference-list/?page_id=12&preview=true#references"><sup>('.$i.')</sup></a>';
    return $return_value;
    return ob_get_clean();
global $my_content;
$my_content = add_shortcode( 'ref', 'ref_shortcode' );

function references_shortcode( $atts , $content = null ){
    global $my_content;
    return '<li>' . $my_content . '</li>';
    return ob_get_clean();
add_shortcode( 'references' , 'references_shortcode');

I have no issue with the function for the “ref” shortcode, if there’s some way I can get content inside it to the “references” shortcode that would be great!

woocommerce offtopic – How to filter products that has custom filters inside shortcode properties?

I´m new in wordpress and woocommerce development and I understand the basics of hooks and configurations.

I´m using a template that uses WPBakery Page Builder, that generates shortcodes that builds many sections (rows, cols, and more complex like products), and you can update the shortcode mapping to include new properties to your code, so what I did is to add a new option to filter products with an attribute called season. A client wanted to have a section of products in the home page that needs to be filtered by the season (winter, spring, summer or fall) and have the section like “Season’s Products”. So right now I have the property added in the vc_map() related to the products filtering options.

And this is the result I have when saving the page with the selected season:

(thb_product product_sort="by-season" season_id="spring" item_count="6" thb_style="thb-carousel" columns="4" thb_navigation="")

this is now creating a normal row of products, but it´s obviously not showing the products of the season filter.

What´s the next step I need to make? how can I filter the product_sort field for a custom value? do I need to add a hook to update the query?

plugins – Get shortcode attrs inside AJAX callback function

I need to get the attribute values passed to the shortcode inside an AJAX callback function.
With my attempts I get all NULL values. I don’t understand where I’m wrong.
Everything is within a class.

Here is the code (some rows are omitted to simplify)

class MyPlugin

    private $id;
    private $delimiter;
    private $file;
    private $type;
    private $width;
    private $height;
    private $values;


    public function __construct()

    public function starter()

        add_shortcode('show_map', array($this, 'shortcode_func'));
        add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
        add_action('wp_ajax_nopriv_searchInMap', array($this, 'render'));
        add_action('wp_ajax_searchInMap', array($this, 'render'));

    public function enqueue_scripts(){
        wp_register_script('leaflet-script', plugin_dir_url(__FILE__) . 'js/leaflet.js', array(), '1.0', false);

        wp_register_script('cluster-script', plugin_dir_url(__FILE__) . 'js/leaflet.markercluster.js', array('leaflet-script'), '1.0', false);

        wp_enqueue_script('ajax-map', plugin_dir_url(__FILE__) . 'js/ajax-map.js', array('jquery'), '1.0', true);

        wp_enqueue_style('leaflet-style',  plugin_dir_url(__FILE__) . 'css/leaflet.css');
        wp_enqueue_style('cluster1-style',  plugin_dir_url(__FILE__) . 'css/MarkerCluster.css');
        wp_enqueue_style('cluster2-style',  plugin_dir_url(__FILE__) . 'css/MarkerCluster.Default.css');

        global $wp_query;
        wp_localize_script('ajax-map', 'var_ajax_map', array(
            'ajaxurl' => admin_url('admin-ajax.php'),
            'query_vars' => json_encode($wp_query->query),
            'nonceMap' => wp_create_nonce('nonce-render-map'),
            'shortcodeValues' => json_encode($this->values)

    public function shortcode_func($atts)

                'id' => '',
                'file' => '',
                'delimiter' => ';',
                'type' => 'normal',
                'width' => '100%',
                'height' => '600'


        // class RenderMap: get values from a CSV file and render a map with markers 
        $map = new RenderMap($id, $file, $delimiter, $type, $width, $height);

        $this->id = $id;
        $this->file = $file; // Example: filename.csv
        var_dump($this->file) // You get right value here, not NULL
       //below another try to pass values, via $_POST
        $this->values = array(
                 'file' => $file,
                'delimiter' => $delimiter,
                'type' => $type,
                'width' => $width,
                'height' => $height
        // class SearchInput: render the search form
        $searchInput = new SearchInput();

        $out = $searchInput->render() . '<div id="map-div">' . $map->get_map() . '</div>';
        return $out;

    // AJAX callback
    public function render()
        $text= $_POST('text');
        check_ajax_referer('nonce-render-map', 'nonce_map');

        var_dump($_POST('shortcodeAttrs')); // value: NULL
        $map2 = new MqfRenderMap($this->id, $this->file, $this->delimiter, $this->type, $this->width, $this->height); // Map not rendered, all function parameters are NULL... What's wrong?
        echo $map2->get_map($text);



Content of ajax-map.js

(function ($) {

    $(document).on( 'click', '#map-search-button', function( event ) {

      valSearchInput = $('#map-search-input').val();

        url: var_ajax_map.ajaxurl,
        type: 'post',
        data: {
          action: 'searchInMap',
          query_vars: var_ajax_map.query_vars,
          nonce_map: var_ajax_map.nonceMap,
          text: valSearchInput,
          shortcodeAttrs: var_ajax_map.shortcodeValues

        beforeSend: function () {

        success: function (html) {




Any help is appreciated. Thank you

woocommerce offtopic – How to add a shortcode which runs a .php file for the current post

My client is using Woocommerce Bookings for tours which are saved as Woocommerce Products. I have just redesigned their site using a page builder for ease of future updates, etc for them. However, I cannot for the life of me work out how to get the Woocommerce Booking form onto the newly designed Single Product Template page! There appears to be no shortcodes included natively…

I have the .php file which runs to pull the form in, and I have found instructions on how to add a new shortcode using the page builder. However, I have no idea what to put inside the shortcode creation to get it to run the form .php code – further complicated by my needing it to run for the current product at the time….

Here is the code to create the shortcode

function wpc_elementor_shortcode( $atts ) {
    echo "This is my custom PHP output in Elementor!";
add_shortcode( 'my_elementor_php_output', 'wpc_elementor_shortcode');

Happy to provide further information if needed!

php – post meta value as shortcode parameter

i am using a plugin (download monitor) to display downloads via shortcodes. also using an addon for download monitor – gravity forms lock. for that, the shortcode, which i must include in the same post is like this: (dlm_gf_form download_id="download-form-id") where download-form-id would represent the post meta name.

i’d like to be able to modify the download form ID parameter within the shortcode via a custom field value.

i found this in the ‘gravity forms lock’ add-on for download monitor:

// hijack the download shortcode add_shortcode( 'dlm_gf_form', array( $this, 'shortcode_dlm_gf_form' ) );

i’m hoping there is a method to filter or hijack the shortcode for the forms as there is for the standard download shortcode.


plugins – get_post_meta shortcode returns empty field

I’m trying to create a custom shortcode that will allow me to input custom order field data into an auto generated outbound email template via the Custom Order Status for WooCommerce plugin.

My understanding of PHP is limited at best but I came up with is a modified version of the below code that came from a similar question previously answered by Krzysiek Dróżdż:

function wcal_abandoned_cart_id_shortcode_callback( $atts ) {
    $atts = shortcode_atts( array(
        'post_id' => get_the_ID(),
    ), $atts, 'wcal_abandoned_cart_id' );

    return get_post_meta( $atts('post_id'), 'wcal_abandoned_cart_id', true );
add_shortcode( 'wcal_abandoned_cart_id', 'wcal_abandoned_cart_id_shortcode_callback' );

WordPress and the plugin seem to recognize the shortcode (wcal_abandoned_cart_id) however the output value is blank. The value that should return for this specific order is “428”. I’m hoping someone can help point me in the right direction.

Thanks in advance.