Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Nick Hooper
Nick Hooper
7,188 Points

Trouble with dynamic sidebars in wordpress

Hi, I am trying to make a dynamic sidebar in wordpress a little more dynamic by automatically selecting which sidebar it uses from funtions.php depending on what the title of a page is.

When I use something like this it works just fine to display a single static sidebar.

dynamic_sidebar('blog')

I have another sidebar called "test" that works when I replace "blog" with "test".

Now I want to use this code below. "the_title" returns with the post title in this case "test", but it doesn't seem to work.

dynamic_sidebar(the_title)

the_title does work and I have tested in other situations such as in an alt attribute of an image and it gives the correct value.

What am I doing wrong?

1 Answer

Nick Hooper
Nick Hooper
7,188 Points

I figured it out after reading the codex a bit.

I had to use get_the_title() instead.