0

I need to execute a shortcode at the TOP of contents area in specific PAGE template.

Notice that I'm talking about "pages" as there are lots of plugins for 'posts'

Preferably inserting the shortcode somewhere between the page title & the actual contents of that page.. << if that's at all possible? :)

So, does anyone know how to edit the Full Width Page Template (page-full.php) to include a shortcode (that is executed by another plugin) if the page is the full width?

Thanks,

Mary

5
  • 1
    Follow-up question: "Preferably inserting the shortcode somewhere between the page title & the actual contents of that page" --> If you type the shortcode in the first line of the page body in the WYSIWYG-Editor, that's exactly what should happen, no?! Can you clarify how what you are asking is different from that scenario? Commented Jun 26, 2013 at 15:41
  • @JohannesPille : I assumed it needed to be automatic, for every post/page, but I think there may also be markup concerns that complicate things.
    – s_ha_dum
    Commented Jun 26, 2013 at 16:13
  • @s_ha_dum hi.. Thanks for your help... OK, the shortcode is like this: <!--date--> So, when I paste this to the WYSIWYG, I get the date (when I see preview the page). Now... I tried to put this inside the page template: echo do_shortcode('<!--date-->'); It appeared AS TEXT (not executed)... and it appeared where I wanted (after the title & before the contents). But how to make it just show the VALUE, something like: 26/06/2013 The shortcode is working, This value shows up, if I paste the shortcode in the edit area of the page.
    – Mary
    Commented Jun 26, 2013 at 16:23
  • @JohannesPille yes the shortcode works fine when I type it into the editor... but I needed 2 things... 1 wanted to add it's value after the title and before contents... which cannot be done unless I edit the template itself. Second thing is that I needed this to be permanent (i.e. instead of adding the shortcode everytime I write a page), so it appears on that location (between title and contents) in all pages of specific template. Hope that helps :)
    – Mary
    Commented Jun 26, 2013 at 16:26
  • @Mary : See the edit to my answer.
    – s_ha_dum
    Commented Jun 26, 2013 at 16:33

1 Answer 1

0

The do_shortcode function accepts a string, searches the string for shortcodes, and processes any that are found. That means that...

// Use shortcode in a PHP file (outside the post editor).
echo do_shortcode('[gallery]');

... is all you need to run a shortcode (code taken from the Codex).

Your request that the shortcode be inserted "somewhere between the page title & the actual contents of that page" is not precise enough to allow for a good answer. There are only a few somewhat reliable theme hooks and none of them are really "between" the title and the content. The best you could do is probably to try to insert the shortcode immediately before the content.

function inject_shortcode_wpse_104354($content) {
    return '[shortcodename]'.$content;
}
add_filter('the_content','inject_shortcode_wpse_104354');

The template you mention-- "Full Width Page Template (page-full.php)"-- is part of your theme. Not knowing what theme, no comment is possible.

Per a comment:

OK, the shortcode is like this: So, when I paste this to the WYSIWYG, I get the date (when I see preview the page).

That is not a shortcode. Shortcodes use square brackets. You have a plugin that has cooked up its own shortcode-like functionality, or your theme has done so.

You can try...

echo apply_filters('the_content','<!--date-->');

... where you want the date pseudo-shortcode to execute.

But I think a better approach is to find the function that processes <!--date--> and try to use that directly. I am afraid I don't where to look for that exactly, but you should have some idea of what plugin is doing this.

3
  • I was calling it "shortcode" because the plugin documentation was calling this as a shortcode :) I pasted the code you edited, but again it shows as TEXT like this: echo apply_filters('the_content',''); without the <!--date--> part as you see. Is there is a specific location where I have to paste this? as I'm pasting it now below a line that looks like this <h2 style="margin-top: 40px;"><?php the_title(); ?> </h2> which is to retrieve the title of that page.
    – Mary
    Commented Jun 26, 2013 at 16:45
  • That is PHP. It has to be inside PHP opening (<?php) and closing (?>) tags.
    – s_ha_dum
    Commented Jun 26, 2013 at 16:50
  • ^^^ That made it WORK! :) sorry but what seems so obvious to you, may not be the same for non-techies like myself... thanks again, now the date is executing after the title & before the content. Good job :)
    – Mary
    Commented Jun 26, 2013 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.