WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a short code called [contianer-narrow][/container-narrow] which wraps your content in a twitter bootstrap class: .container-narrow the issue is that the page title is not included. is there a way to say:

if this short code is used, include the page title, else forget it?

share|improve this question
How are you using it? Are you editing template files? Could you post the full function that the short code calls? – Andrew Bartel Apr 29 '13 at 18:23
As above, post your code please. – t31os Apr 29 '13 at 18:28
Are you wanting to switch the display of the title inside the shortcode or somehow make the shortcode control the display of the title elsewhere in the page template? It sounds like the latter. – s_ha_dum Apr 29 '13 at 18:30

As for your concrete question:
You could theoretically parse the retrieved content before shortcodes are resolved for this specific one, set a flag and wrap the title on condition of that.

But it would make much more sense to trash the shortcode-approach and simply create a new page template.
(Especially so, given that the parsing for the shortcode, or at least its consequences, would have to happen in the used template file anyway)

Copy the contents of your theme's page.php to a new file.
Call that page-narrow.php.
Prepend it by

 * Template Name: Narrow Page

And wrap the copied part in an element with the desired class.

share|improve this answer

I'd try something like this (not tested) :

function has_shortcode( $sc = '' ) {
    global $wp_query;
    foreach( $wp_query->posts as $post ) {
        if ( ! empty( $sc ) && stripos($post->post_content, '[' . $sc) !== false ) {
            return true;
    return false;

Then you can use it like that :

if ( has_shortcode( 'container-narrow' ) {}
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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