Skip to content
Advertisement

WordPress page title fxn in echo p

This is probably super simple but I just cant seem to figure it out.

How can I pass the current WordPress page title into this code?

Below is a snippet from Formidable Forms WP plug-in which basically prints statistics from forms within my website.

In this case, the # of entries for a specific form (55jqi) and a specific field(50) are displayed on the pages, showing how many other people also submitted that form.

Im trying to skip needing to update each page (4,380 pages) with the stats output snippet.. and instead call the current page into the stats display code, to show stats for that particular page being viewed.. using an elementor custom post type template.

I need this:

echo FrmProStatisticsController::stats_shortcode(array('id' => '55jqi', 'type' => 'count', 50 => 'runtz'));

To work like this:

echo FrmProStatisticsController::stats_shortcode(array('id' => '55jqi', 'type' => 'count', 50 => 'single_post_title();'));

Replace the input area ‘Runts’ with the current page title, using

single_post_title()

Or similar.

Any help would be amazing!!

There is also a short code available which works the similarly.

[frm-stats id=55jqi type=count 50="Runtz"] 

Formidable Forms Plugin shortcode and php page for reference: https://formidableforms.com/knowledgebase/add-field-totals-and-statistics/#kb-field-filters

Advertisement

Answer

You are using single_post_title function in a wrong way. By default, this function will echo the output but in the shortcode, you need to return the output.

This function accepts 2 param: 1: $prefix 2: $display

You need to pass $display as false, which will tell the function to return the value.

so you’ll have to make a call like this `single_post_title( ”, false )“

and your shortcode call will be like this:

echo FrmProStatisticsController::stats_shortcode(
    array(
        'id'   => '55jqi',
        'type' => 'count',
        '50'   => single_post_title( '', false ),
    )
);
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement