So, I have the following shortcode which is included in two different pages.

<?php echo do_shortcode('[shortcode]'); ?>

Since two pages are using one identical shortocode, I am thinking of adding a class to the first page so that I can customize the first page shortcode only.

So here is my question.

  1. Do you think that adding a class to the shortcode in the first page would allow me to customize it?

  2. If so, what is the proper way of adding a class to the above code?

  3. If not, what would be an option to add customization to a shortcode for only specific page?



If it really is just for one page you could use a conditional on the_ID(); from within your shortcode class (it is a custom shortcode right?)

$class = the_ID() == 213 ? "some-other-class" : "";
$myhtml = sprintf("<div class='some-class %1$s'>%2$s</div>",

The other option is to add parameters or "attributes" to your shortcode as in the codex. See: http://codex.wordpress.org/Shortcode_API

Hope that helps.

  • 2
    the_ID() echoes the ID. You need get_the_ID(). – fuxia Mar 19 '15 at 14:39

Wordpress already has these classes in place for you, so you can basically target a specific page in CSS without adding additional classes. Take a look at the default body_class section in the codex, and more particulary at the pages section


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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