WordPress.org

Ready to get started?Download WordPress

Forums

Adding Title in Text Widget (7 posts)

  1. ronbme
    Member
    Posted 6 years ago #

    How do I add a title to a text widget using php?

    I'm trying to add php code to a text widget so that the title will reflect what page I am on. I have php code for the content which works.

    The problem is that the code for the title in the text widget is stripped away when I save the sidebar.

  2. kmessinger
    Volunteer Moderator
    Posted 6 years ago #

    AFAIK, php won't work in a text widget. html and java will.

  3. ronbme
    Member
    Posted 6 years ago #

    It will if you have the Exec-PHP plugin installed.

    I've got the php code working in the content section of the text widget. I have another plugin, "Page Sidebars", which lets me add a sidebar for any page with content specific to that page.

    Then I just add the php code for the title and the php code for the content and it reads whatever I have typed specific for a certain page.

    The content part works fine but the title is being stripped. I think the title is being "sanitized" when I save the text widget, and that strips away my php code for the title.

    I need a way to save that php code for the title so it doesn't get stripped.

    I suppose I could also come up with something to eliminate the title from the text widget and then recreate the title in the content part.

  4. kmessinger
    Volunteer Moderator
    Posted 6 years ago #

    Yes, apparently your php does not work for titles.

    I didn't like the titles on my sidebar and I wanted them all to match so I did just what you are thinking about - made them part of the content. I know that is the lazy way out but it was all I could think of at the time.

  5. ronbme
    Member
    Posted 6 years ago #

    Thanks. Can you explain how you did yours?

  6. kmessinger
    Volunteer Moderator
    Posted 6 years ago #

    BTW, not in my current blog but one I have stopped posting to . . .

    I used one text widget and put titles in like this <span class="newsheader2"><strong>From the video section</strong></span><br />
    then my java script or html
    then the next title, etc.

  7. ronbme
    Member
    Posted 6 years ago #

    Thanks.

    I'll have to play around with it. I am using the theme's title box and am having trouble getting the title inside of the box.

    But, I'm close to solving it.

    Thanks again.

Topic Closed

This topic has been closed to new replies.

About this Topic