How can I edit a default function on WordPress? - php

I should edit the dynamic_sidebar() function on wordpress (hiding some categories, editing the template).
Is it possible? I read "you need to edit the core", but I don't have understand where is this "core" :)

Never edit the core. The reason is that if you change the default behaviour, themes you install might not work and updates to the wordpress engine will break your changes.
To change the way your wordpress behaves, create a child theme. Then add a functions.php file and in it create a widget that has your desired behaviour.
You can also register a new type of sidebar and a page templates that shows only that type of sidebar.
See: http://codex.wordpress.org/Child_Themes and https://codex.wordpress.org/Function_Reference/register_sidebar_widget

Personally, you sound like your just starting out so I will give you some advice. Never edit the core.
It's tempting for a quick fix. Everyone has done it when they didn't know any better, but you have the opportunity to learn the right way.
Approach your problem logically. What are you trying to edit it for? Hiding some categories? Use the internal widget system in the CMS and take them off. Delete the categories, or hide them with CSS {display:none;}.
Good luck my young Padawan. I hope you take some advice and heed it well.

Best way is to probably make a Child template using the plugin One-click child theme. Copy the file containing the function to the child template (using ftp) and edit it there. This way you can update your template and still keep your changes.

Related

Is it possible to hook a text box into a WordPress theme, via the functions.php file?

I am currently using a WordPress theme to create an ecommerce website. I am looking to create a horizontal text box, with 3 columns, to appear directly beneath the Main Menu navigation. Rather than edit the header.php file, and risk breaking the theme, is it possible to achieve this by hooking into the theme, via a functions.php file in the child theme or would thus be bad practice?
So adding "right after the main menu" is not something WordPress will be able to give you directly, no. Because, by definition, the structure of a page is a theme's responsibility.
That would be a perfect case for a child theme, and it would be my first choice. There you can safely override the index file (or header file, depending on how the theme is built) and add your html to it.
Another option a child theme might give you, is adding html through the theme's own filters and actions - but that will totally depend on your theme giving you such hooks.
Finally, if truly you want to add right after the main navigation, you might look at the wp_nav_menu filter: using that, it should be possible to first detect if you are looking at the main navigation or not, and if you are, append your own html. But frankly, I think the risk of breaking your layout is greater with that method.
Hope this helps!

How do I customize content in the WP starter theme Roots?

I am fairly new to WP and very new to Roots (http://roots.io/) and I am having trouble creating a custom home page. Here's how far (I think) I understand it:
To create a custom home page I put a file named "front-page.php" in the WP root directory. This file is based off of "page.php".
"front-page.php" loads "content-page.php" from the templates directory.
And that's where it gets a bit fuzzy to me. The function "the_content()" lives in "content-page.php" and I'm assuming it loads the content of the page but it's loading some default stuff (I think it's added by the Roots theme) that I don't want there. I don't think the proper way to customize the home page content is to modify "content-page.php" and remove or change the function "the_content()". I'm assuming there is a better, modular way to do this, possibly creating a custom class that will be loaded when "the_content()" is called but I don't know where and how to do that.
As you're a bit vague with the details I'm going to have to read between the lines a bit. If you need further clarification just ask:
the_content() just outputs the content stored for a particular post, which you would edit in the WP admin. In terms of editing the markup that surrounds the content you have a couple of options. You could edit content-page.php as you require, or create a new partial (such as content-home.php and load that instead.
You can also use filters for modifying content; these are often used to change content that appears in multiple places such as 'read more' links. Check out this introduction to filters for more info.
In closing, you don't want/need to edit the_content()

Wordpress Theme manipulation - Remove Widget Background

So I know this is a bit out of ordinary for me to ask a question like this, but for some reason I am just really having an issue grasping this.
My Problem:
I have a responsive layout theme for word press, its clean its pretty. When implementing Google ad-sense into a text/html widget on the right bar it over runs the widget size and over hangs on the right hand side.
My Question:
What will be the best method for getting my ad to look more uniform. Is there a way to select a single widget css? Is there a way to put a div inside that widget and select the parent css from that div? Should I go in and hard code it into the theme?
Additional:
The theme I am using has a built in child theme option which I have chosen to use. When I place the code into the child themes function.php it breaks the theme and displays what I enter as plain text to the screen. Adding opening and close php tags did not seem to fix this issue.
Well it appears once again I asked a question before fully digging my brain into this. Hopefully this will become something useful for someone else.
FIX:
It appears that wordpress assigns a unique ID to every widget that is created.
Created New Text Widget
Wordpress Assigns: text-1
I can now go into css and manipulate this widget directly.
#text-1 {
//do somthing
}
It's always best to avoid hardcoding WP themes as when they get updated your modifications might vanish.
Glad to see you figured it out, I was going to say that you CAN add a div inside a widget and give it a name, which might still be be better than use the WP assigned layer name, as that might change if you were to delete or re-add the widget.

Drupal 7 theme "front" differs from other pages

I need a custom template for the 'frontpage' and a custom template for all the other pages.
What are the best practices to accomplish this?
Do I need to make 2 themes or can I use the same theme?
Create 2 template files:
page--front.tpl.php for the front page.
page.tpl.php for other pages.
For further reading, check out Drupal 7 Template Suggestions.
Don't forget to clear the site cache after the creation of each new template file.
Hope this helps... Muhammad.
If you're new to Drupal theming, try using the Devel and the Themer Developer module (http://drupal.org/project/devel_themer)
I would like to direct you towards "The Drupal Way" (do it with flexible UI-based modules) if you are not already familiar with.
I would approach this problem using Panels and possibly Views if you need to display listed information on the page (such as a news-feed or similar).
This gives a whole different approach to setting up your site's content displays and it is the general direction of the Drupal ecosystem.

Add custom content to a wordpress theme template

I'm in the process of customising a theme (styling, css, etc). However, I ran into a small problem, basically I wan't to include an introductory message at the top of the home/index template, and then have it as an option(text area) in the theme options panel. How do I go about doing this. Sorry for the noobish question, haven't found any straightforward solution yet. Thanks.
This is a significant customization that will require changes to the PHP code for the theme. You need a PHP programmer, preferably one who knows WordPress.

Categories