This issue is driving me crazy.
This morning, the Wordpress theme I'm creating included a very simple functions.php file, and my site worked properly. Today, I wrote a new function to iterate through categories and list certain posts, and that's the only change I made to functions.php.
After uploading the revised functions file to the server, I get a 500 error every time I access my site. I though, "OK, my new function broke something. I'll just remove it from functions.php and start over." However, after reverting to the original version of the file (the version that worked this morning), I'm still getting the 500 error.
If I remove functions.php from the server, my pages load (without their sidebars obviously, but they load). As soon as I upload the file again (same version that worked this morning), I get the 500 error.
I checked the error log, and I've found that, when I have functions.php on the server, Wordpress (or php more likely) can no longer find the get_template_directory_uri() function. I've done nothing to alter any of the standard Wordpress functions, and this only happens when I've got functions.php uploaded.
What might be causing functions.php to break the standard functions?
Here's my functions.php file:
<?php
/* *********************************************
* Create left-hand sidebar for single.php
*
* TODO: Finalize $sricks_single_left_sidebar.
* ********************************************/
$sricks_single_left_sidebar = array(
'name' => 'Left Sidebar',
'id' => 'lt-single',
'description' => 'This is the sidebar on the left side of the single.php template page.',
'before_widget' => '<!-- Left-Single Sidebar --><div class="lt-single">',
'after_widget' => '</div> <!-- End Left-Single Sidebar -->',
'before_title' => '<h1>',
'after_title' => '</h1>',
);
register_sidebar( $sricks_single_left_sidebar );
/* *********************************************
* Create header_search sidebar to be used on
* all pages
* ********************************************/
$sricks_header_search_sidebar = array(
'name' => 'Header Search',
'id' => 'header-search',
'description' => 'This is the search box in the page header.',
'before_widget' => '<!-- Header-Search Sidebar --><div class="header-search">',
'after_widget' => '</div> <!-- End Header-Search Sidebar -->',
'before_title' => '<h1>',
'after_title' => '</h1>',
);
register_sidebar( $sricks_header_search_sidebar );
?>
To find the cause of issues in WordPress when you get 500 level errors, a blank white screen, or any other strange or unexpected behavior, define the WP_DEBUG constant in wp-config.php.
Like this:
define( 'WP_DEBUG', true );
If you're developing or making changes to a site, it's usually a good idea to enable this feature until you're done editing. It can make it very easy to spot and correct mistakes that could otherwise vex for hours.
Thanks everyone, especially Spencer Cameron. It turns out I forgot the open and close parentheses in my new function's declaration. Wordpress reads functions.php before any of the built-in functions, so it just got stuck there.
When I submitted my code, I left out my new function because I had deleted everything from the body of the function; what could go wrong? Lesson learned...
Related
I am using a function to create my own widget in a custom theme, like this:
function my_sidebar_widget() {
register_sidebar( array(
'name' => 'My Sidebar',
'id' => 'my-sidebar-widget',
'before_widget' => '<div class="my-sidebar-widget">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'my_sidebar_widget' );
This works fine, mostly. The problem is that when my theme is activated on a fresh instance of WordPress, this widget automatically adds in a search bar, recent posts and recent comments.
My question: Is there a function that can remove the content of all widgets (or specific widgets)? Or at the very least, a function that lets you dynamically add default content into the widget (I'd just make it display an empty space)?
Just to be clear, I don't want to unregister the widget, I just don't want it to automatically add in a search bar, recent posts and recent comments.
I've seen some very convoluted solutions to this problem, but after looking in the database I realised there is a much easier way.
Upon theme activation, just update this option with nothing:
update_option( 'widget_block', '' );
Problem solved. Just bear in mind that this will blank the widgets every time the theme is activated.
I am trying to remove numbers from pagination links on a paginated Wordpress post to leave only next/previous buttons. I have the code as follows and it still does not work as required. If I set a display:none; css rule to the tags within the .paging p class this affects all links including the next/previous links as the links do not have a separate class to them.
<?php
wp_link_pages(array(
'before' => '<p class="paging" style="margin-bottom: 5em;">' . __(''),
'after' => '</p>',
'next_or_number' => 'next', # activate parameter overloading
'nextpagelink' => __('<span class="pagelink right">NEXT</span>'),
'previouspagelink' => __('<span class="pagelink left">PREVIOUS</span>'),
'pagelink' => '%',
'echo' => 1 )
); ?>
Here is an example of a post illustrating the problem: http://famtrav.staging.wpengine.com/destinations/uk/15-fun-things-july-2016/
Is there another way of me achieving the required result? I hope this makes sense. Many thanks.
I have now solved this. The problem was caused by conflicting code. Specifically the wp_link_pages function was being defined both in the themes functions.php file and in the post-template.php file within the /wp-includes/ folder with instructions in one incidence contradicting the other. I commented out the instructions in the functions.php file and altered the post-template.php file with the correct code and this solved the problem.
I am desperately trying to remove the bullets that appear in front of the flags. I am using WordPress and I've added this Polylang feature as a widget in my header. I tried to post a screenshot but I can't upload images yet.
I would also like to custom css this widget but I have tried everything I can think of and nothing is happening. Basically this is placed on the left side of my page when I want it on the right side. Here is the code I used in the my_functions php:
function my_widgets_init() {
) );register_sidebar( array(
'name' => __( 'Header Area', 'your-theme' ),
'id' => 'sidebar-2',
'description' => __( 'An optional widget area for your site header', 'your-theme' ),
'before_widget' => '<div id="%1$s" class="headwidget %2$s">',
'after_widget' => "</div>",
'before_title' => '<h3>',
'after_title' => '</h3>',) );
}
add_action( 'widgets_init', 'my_widgets_init' );
And here is the code used in header.php
<div class="span12" id="polylang-2">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar-2') ) : ?> <?php endif; ?></div>
I tried entering Custom CSS from the WP admin widgets panel, i have no idea how to code from here I guess cause nothing ever changes... I have already done a lot of customization to my site so I am ok with CSS, it's more finding where to make changes I have trouble with. And php is not my forte yet.
Thanks for all your help.
you can inject a custom class after widget class as shown in the code below:
'before_widget' => ''
now you can call the class myclass from style.css file present in your theme folder I hope you know how to remove the bullets in the css
you can locate your theme files from wp-content/themes/themename
.myclass {float:left;} /* to move it on the left */
.myclass ul {list-style:none;}
Moreover you dont require a div with the id polylang-2 since the div automatically comes from the above widget code.
and you can change the header.php code to
<?php dynamic_sidebar("sidebar-2");?>
OR
the next way around is if you want to use your existing code then add the following css in your style.css file inside your theme
#polylang-2 ul {list-style:none;}
Let me know if it solves your problem or not. Thanks
I built a custom wordpress theme, and I also built a custom widget sidebar (so widgets are enabled), I can see the title of the widget, but the content is not showing. For example I'm using a poll widget, the title is exactly as I've set it, but the content is completely blank.
In the header the scripts for the plugin are loaded, but again there is no content. I tried multiple plugins, and they all do the same thing. I also attempted this with using do_shortcode() and again, no content. So I am stumped.
I have also tried getting support on the wordpress forum, but I've never successfully gotten an answer to my query there.
My hope is that someone has had this same issue, and can point me to what the problem may be.
In the header, i've included the following information:
<html <?php language_attributes(); ?>>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<?php wp_head();?>
<?php wp_meta();?>
<?php wp_print_scripts();?>
However again, no results. Google searches have also not pulled up anything about this being an issue. Here's the odd thing, I design all wordpress themes the same way, most of which are all hosted on the same server, and this is the only theme having this problem.
Also I've included my functions.php script for reference purposes.
<?php
function twentyten_widgets_init() {
register_sidebar( array(
'name' => __( 'Primary Widget Area', 'twentyten' ),
'id' => 'primary-widget-area',
'description' => __( 'Add widgets here to appear in your sidebar.', 'twentyten' ),
'before_widget' => '<div id="spacer">',
'after_widget' => '</div></div>',
'before_title' => '<div id="left_top">',
'after_title' => '</div><div id="left_bottom">',
) );
}
add_action( 'widgets_init', 'twentyten_widgets_init' );
add_filter( 'show_admin_bar', '__return_false' );
remove_action( 'personal_options', '_admin_bar_preferences' );
?>
EDIT **
I removed from the header as it was causing duplicate scripts in the header. So that is no longer an issue, however that did not resolve the issue and nothing has changed as a result of being removed.
From your code all your widget will look like:
<div id="spacer">
<div id="left_top">Title</div>
<div id="left_bottom">
CONTENT
</div></div>
You are using id's here (maybe you intend to use classes) here for your elements, like id="left_top". So adding more than one widget will give you a problem, see Can multiple different HTML elements have the same ID if they're different elements?, cause the id's should be unique.
You will maybe apply a css / javascript on one of these id's like
#left_bottom{display:none} this will explain why your content will be not shown independent of the widget you use.
I'm trying to diligently follow what the codex says about modifying the appearance of the comments form (located here) but I can't get it to work. The default comments form appears despite my array of arguments that should change it.
In the template I have: comments_template('mycomments.php');
Then...
<?php
//inside my mycomments.php file
$comment_args = array (
'fields' => array('author', 'email'),
'must_log_in' => true,
'title_reply' => 'Review this product',
'label_submit' => 'Submit',
);
comment_form($comment_args, $post->ID); ?>
Am I doing something wrong?
I figured it out. There was nothing wrong with my arguments. Instead... I needed a / infront of the relative link to my customized comments template:
comments_template('/mycomments.php');
Moral of the story: If you're having trouble getting the template to work (at all), make sure you're actually loading the right template file!