WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Editing the functions.php code messed up my sidebar (14 posts)

  1. temeraire
    Member
    Posted 1 year ago #

    Hi,

    I have caused this very stupid and strange problem to my wordpress site:

    I was messing around with the code in functions.php (I shouldn't do that not being a programmer, I know). What I was trying to do is irrelevant to the problem I'm describing.

    Anyway, I pasted a bit of code in functions.php which resulted in the following:

    - My dynamic sidebar turned to my default, static sidebar (widgets disappeared)
    - Through my WP back-end I do not have access to Widgets any more -- it tells me "The theme you are currently using isn’t widget-aware" etc, as if I have never had a dynamic sidebar.
    - Removing the code that caused the problem did not result in reverting this change.

    The code I pasted is this:

    function search_excerpt_highlight() {
        $excerpt = get_the_excerpt();
        $keys = implode('|', explode(' ', get_search_query()));
        $excerpt = preg_replace('/(' . $keys .')/iu', '<strong class="search-highlight"></strong>', $excerpt);
    
        echo '<p>' . $excerpt . '</p>';
    }
    
    function search_title_highlight() {
        $title = get_the_title();
        $keys = implode('|', explode(' ', get_search_query()));
        $title = preg_replace('/(' . $keys .')/iu', '<strong class="search-highlight"></strong>', $title);
    
        echo $title;
    }

    Any ideas?

  2. fonglh
    Member
    Posted 1 year ago #

    Put your whole functions.php code in a pastebin and copy the URL here so someone can take a look at it.

    You probably messed it up when removing it.

    If you have a backup copy of the file, just replace it.

  3. temeraire
    Member
    Posted 1 year ago #

    Hi fonglh,

    Thanks for the comment.
    No, it was messed up when I pasted the new code in: I checked it when I pasted it, and again when I deleted it.

    Also, I was very careful to remove only the code I pasted, I am 100% sure of that.

    Original functions.php code:
    http://pastebin.com/uttK7Afe

  4. alchymyth
    Forum Moderator
    Posted 1 year ago #

    that functions.php looks generally as if some code is missing from its end; and it has no 'register_sidebar()' codes.

    what theme are you using, and is this the unedited functions.php from the theme?

  5. temeraire
    Member
    Posted 1 year ago #

    Thanks for having a look alchymyth.

    Yes, this is the original, unedited, untouched functions.php from Starkers framework, which I have been trying to modify (the framework that is, not the file). I only pasted the extra code in and then deleted it.

    Any idea what might have gone wrong?

  6. alchymyth
    Forum Moderator
    Posted 1 year ago #

    it seems that starkers does not have a sidebar and dynamic widgets enabled (afaik).

    are you sure you had the dynamic sidebar in your starkers theme before you edited the functions.php?

  7. temeraire
    Member
    Posted 1 year ago #

    Indeed, this looks strange.
    I did have a dynamic sidebar before with widgets and everything, which worked fine.

    Maybe I have done something fundamentally wrong, such as using the wrong file or something like that, I cannot explain this otherwise.

    I'll have to go through the whole thing again, and check the files I'm using... I'll post the outcome here when I have news on this.

    Thanks alchymyth.

  8. temeraire
    Member
    Posted 1 year ago #

    Update:

    It turns out the original file is exactly the same as mine, nothing wrong there. This is the file:

    https://github.com/viewportindustries/starkers/blob/master/functions.php

    So this is not resolved yet...

  9. alchymyth
    Forum Moderator
    Posted 1 year ago #

    the original file is exactly the same as mine

    I had checked that github as well, and there is no hint of a sidebar in the templates;

    So this is not resolved yet...

    there is possibly nothing to resolve as there is nothing wrong (with starkers per se).

    where did you get your 'sidebar' code from?

    which template is showing the sidebar, and what is its full code?

  10. temeraire
    Member
    Posted 1 year ago #

    where did you get your 'sidebar' code from?
    which template is showing the sidebar, and what is its full code?

    I created sidebar.php to make it dynamic following instructions from WP.org. The file sidebar.php contains the following code:

    <ul id="sidebar">
    	<?php if ( !dynamic_sidebar() ) : ?>
    				  <li><h1>about</h1></li>
    				  <li class="blogposts"><h2><?php _e('recent blog posts'); ?></h2></li>
    						<ul>
    							<?php wp_get_archives('type=postbypost&limit=1'); ?>
    						</ul>
    				  <li><h3>item 3</h3></li>
    				  <li><h4>item 4</h4></li>
    	<?php endif; ?>
    	</ul>

    Please note again that I did have a dynamic sidebar with widgets which worked, using the above code and the original functions.php
    ( https://github.com/viewportindustries/starkers/blob/master/functions.php )

    I can't really understand what the code I tried to use did to the whole thing...

    Can you tell what went wrong?

  11. alchymyth
    Forum Moderator
    Posted 1 year ago #

    you probably need to add at least one line to functions.php:

    register_sidebar();

    http://codex.wordpress.org/Function_Reference/register_sidebar

    http://codex.wordpress.org/Widgetizing_Themes

  12. temeraire
    Member
    Posted 1 year ago #

    OK, this is strange: This line of code solved my problem -- thanks!

    But this code wasn't there to begin with, and the dynamic sidebar worked. How do you explain that?

    I really appreciate the help though! Problem solved.

  13. deeve007
    Member
    Posted 1 year ago #

    Sorry, not sure what you're on about, but the current Starkers theme does not support dynamic sidebar, so nothing would have worked until you added the relevant code.

  14. temeraire
    Member
    Posted 1 year ago #

    I know what you mean deeve007. I also understand why you are confused:
    Believe it or not, I had left out the line

    register_sidebar();

    from functions.php altogether (due to inexperience with WP of course) but my dynamic sidebar worked fine, complete with widgets and everything!

    Then I added a piece of (irrelevant) code to functions.php, then deleted it again, and that's when the dynamic sidebar stopped working, as you describe.

    Very strange problem, I guess there's some kind of bug that causes confusion in the communication between what you do through the WP admin panel and the php files...

    ( Can I just note again that my original problem has been solved by adding the above bit of code to the file functions.php )

Topic Closed

This topic has been closed to new replies.

About this Topic