In a post, I have this text:

[bhours shortcode="test" title="test"]

But the "title" attribute appears to be ignored. Here's a var_dump of the $atts attribute array

array(1) {
  string(4) "test"

Here's the PHP code:

function bhour_shortcode_handler($atts){
    global $post,$bhourdays;


    echo var_dump($atts);

    if(isset($atts['shortcode']) && !empty($atts['shortcode'])){

        if(isset($atts['title']) && empty($atts['title'])){
        elseif(isset($atts['title']) && !empty($atts['title'])){
            //get title from post           


    $output.='<p>this is a test</p>';

    return $output;

add_shortcode('bhours', 'bhour_shortcode_handler');

Is the "title" attribute some sort of reserved word?


It appears that you are not extracting your $atts correctly or at all for that matter.

Use the correct procedure to get access to the passed attributes allong with setting up defaults as a fallback:

extract( shortcode_atts( array(
    'shortcode' => 'default_value',
    'title' => 'Default Title',
), $atts ) );

There is infact an extensive guideline on shortcode attributes in the Codex, http://codex.wordpress.org/Shortcode_API#Attributes

When in doubt just copy the WP examples and take if from there.

| improve this answer | |
  • The problem is that I want to be able to tell the difference between [bhours title=""], [bhours title="my title"], and [bhours], so I don't necessarily want to set a default value. – Force Flow Aug 28 '12 at 17:07
  • If I use the code as you suggest, the value of the title attribute does not get passed to the $title variable. However, the $shortcode variable works fine. Again, this brings us back to the original question--why does "title" not appear in the $atts array? After all, you still need it to appear in the array in order to access it with the extract function. – Force Flow Aug 28 '12 at 17:17
  • Perhaps title is reserved somehow? Test you short code with more than just these two fields and see if 'title' after all is just not going to be an option. – Foxinni Aug 29 '12 at 10:18
  • That was my question. I tried [bhours shortcode="test" compress="true" title="my title"], but the title attribute still didn't appear. – Force Flow Aug 29 '12 at 12:39
  • I found another interesting thing. If I use [bhours show_title="true"], the show_title attribute doesn't appear. if I misspell "title" like this: [bhours show_ttitle="true"], then the attribute show_ttitle` appears. There is something strange happening whenever I use the word "title" in an attribute--it seems like it's ignored every time for some reason. I don't understand it. – Force Flow Mar 6 '13 at 15:47

I figured out the problem.

I had a function that was stripping the title attribute from the HTML, but couldn't differentiate between a shortcode and an HTML tag.

So, I converted over from regex to DOMDocument.


| improve this answer | |

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.