I want to create a website in wordpress, for this I take a theme and create a child theme.
I copy in the folder of the child a style.css and header.php, because I want to modify the header too. I modify the file of the child.
In my style.css I add the line Template: with the name of the father theme
/*
Theme Name: Example
Theme URI: http://www.woothemes.com/
Version: 1.2.15
Description: Designed by WooThemes.
Author: WooThemes
Author URI: http://www.woothemes.com
Tags: woothemes
Template: mystile
Copyright: (c) 2009-2011 WooThemes.
License: GNU General Public License v2.0
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
I am using this line in the header.php
<?php $logo = esc_url( get_template_directory_uri() . 'images/logo.png' ); ?>
of my child theme to take a images but this line return the url of the father theme no his child!
I take this.
http://localhost/.../wp-content/themes/mystile/images/...
I I want this
http://localhost/.../wp-content/themes/example/images...
any idea
You need get_stylesheet_directory_uri, this function checks first in the child theme directory and then in the parent's. The one you're using only checks in the parent directory.
Bottom line: if a function doesn't behave as you expect, check the Codex. Much probably you'll find out why over there.
Add to functions.php:
// create a URL to the child theme
function get_template_directory_child() {
$directory_template = get_template_directory_uri();
$directory_child = str_replace('storefront', '', $directory_template) . 'child-storefront';
return $directory_child;
}
Related
I want to customize my dashboard by removing WordPress icon and it's menu on the top bar but I have no idea of how it works because am not an expert in WordPress please help me
Create a new file in the WordPress wp-content/plugins/ folder named admin-bar.php then add the following plugin header:
<?php
/*
Plugin Name: Admin Bar
Plugin URI: http://www.sitepoint.com/
Description: Modifies the WordPress admin bar
Version: 1.0
Author: Craig Buckler
Author URI: http://twitter.com/craigbuckler
License: MIT
*/
You can now activate this plugin in the WordPress administration panel. It won’t do anything yet but you can make additions, save then refresh to view the updates.
you can remove existing items with the remove_node() method. For this, we need to create a new function named update_adminbar() which is passed an WP_Admin_Bar object ($wp_adminbar). This function is called when the admin_bar_menu action hook is activated:
// update toolbar
function update_adminbar($wp_adminbar) {
// remove unnecessary items
$wp_adminbar->remove_node('wp-logo');
$wp_adminbar->remove_node('customize');
$wp_adminbar->remove_node('comments');
}
// admin_bar_menu hook
add_action('admin_bar_menu', 'update_adminbar', 999);
https://www.sitepoint.com/customize-wordpress-toolbar/
You can create a custom plugin and upload folder to your server with this one file in it. Make sure to save the file as exact plugin name. For example, "AdminBar.php"
<?php
/*
Plugin Name: AdminBar
Plugin URI:
Description: Code to hide the admin bar for non-admins only.
Version: 1.0
Author: Name Here
Author URI:
*/
function hide_admin_bar_settings()
{
?>
<style type="text/css">
.show-admin-bar {
display: none;
}
</style>
<?php
}
function disable_admin_bar()
{
if(!current_user_can('administrator'))
{
add_filter( 'show_admin_bar', '__return_false' );
add_action( 'admin_print_scripts-profile.php', 'hide_admin_bar_settings' );
}
}
add_action('init', 'disable_admin_bar', 9);
I want to work on a website powered by wordpress. As suggested by Wordpress community, I should be creating a child theme and need to write code on it. So, there would be two css files, one css file would be of parent theme and other would be of child theme. So, when an end-user will request, will there be two css files requests ?
Suppose your theme name is Theme-x
create a folder with name theme-x-child
inside the folder create Three files
1. functions.php
<?php
//
// Recommended way to include parent theme styles.
// (Please see http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme)
//
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array('parent-style')
);
}
//
// Your code goes below
//
2. rtl.php
/*
Theme Name: Theme-x Child
Template:
Right to Left text support.
*/
#import url("../Theme-x/rtl.css");
3.style
/*
Theme Name: Theme-x Child
Description: wordpress
Author: admin
Template: Theme-x Child
(optional values you can add: Theme URI, Author URI, Version, License, License URI, Tags, Text Domain)
*/
That's it if you want you can add the screenshot.png too. it will get the styles from your parent theme.
I created a child theme of the Wordpress rowling theme.
My style.css contains this:
/*
Theme Name: MF2017
Theme URI:
Description: rowling Child Theme
Author: Kathrin Herwig
Author URI: https://schriftbild.net
Template: rowling
Version: 1.0.0
*/
and the functions.php this:
<?php
/**
* Enqueue scripts and styles.
*/
function namescript_scripts() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array('parent-style')
);
}
add_action( 'wp_enqueue_scripts', 'namescript_scripts' );
?>
The child theme's css is loaded on my test-webspace , the class .grau: grey frame around the images is coming from the child theme's css).
But not on the real website. (.grau is not loaded)
I tried everything, but cannot make it work.
It seems it has to do with access rights / file permissions: When I use the browser tools / styles and click on the child theme style.css, or when I click on the link to the CSS file in the source code, I get to see this:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /wp-content/themes/MF2017/style.css
on this server.</p>
</body></html>
So the browser is not allowed to load the styesheet. Check the access rights / file permissions of the file and its folder on that server and set it to public.
May be you mess with Theme Name. Child theme name should be "Theme Name child", like "Rowling Child" Follow this code below,
/*
Theme Name: Rowling Child
Theme URI: http://example.com/rowling-child/
Description: Rowling Child Theme
Author: Kathrin Herwig
Author URI: https://schriftbild.net
Template: rowling
Version: 1.0.0
Text Domain: rowling-child
*/
for more details check this link https://codex.wordpress.org/Child_Themes
I want to modify the Travelify Wordpress Theme.
I want to put some options like Home|Contact Us|Search on the header.
I want to put an image on the footer.
Question
How can I achieve these changes to the theme?
If you want to make a navigation menu on header, you must setting your menu first.
Setting your navigation menu on appearance>menu
You can setting your footer on appearance>widgets
Try SiteOrigin Widgets bundle plugin for more Widgets on your wordpress.
And for a custom CSS, I use SiteOrigin CSS.
First go to 'wordpress/wp-content/theme' folder and generate an directory with similar name as your theme name.Let say theme name is 'travelify' then use child theme name as 'travelify-child'.
Now go to 'travelify-child' folder and add two files i.e.(style.css and functions.php)
Now open style.css from parent theme i.e.'travelify'
copy all css code and paste into new style.css in 'travelify-child' folder.
don't forget to change theme name,description,text domain.
Add 'Template: travelify' in to style.css.....you can add it after anyline in header like after 'Author URI'.
Now save this style.css and open functions.php in 'travelify-child' foder
and paste below code into functions.php
<?php
add_action( 'init' , 'remove_copyright' , 15 );
function remove_copyright() {
remove_action( 'travelify_footer', 'travelify_footer_info', 30 );
}
add_action( 'travelify_footer' , 'new_footer_info' , 30 );
function new_footer_info() {
$output = '<div class="copyright">Copyright © 2016 Your website name.Powered by Wordpress.
Wordpress</div>';
echo $output;
}
?>
What am I doing wrong....this doesnt seem to work... I keep getting the following error
Warning: Cannot modify header information - headers already sent by (output started at /home/puretige/public_html/wp-content/plugins/Pure Tiger/puretiger.php:13) in /home/puretige/public_html/wp-includes/option.php on line 568
Warning: Cannot modify header information - headers already sent by (output started at /home/puretige/public_html/wp-content/plugins/Pure Tiger/puretiger.php:13) in /home/puretige/public_html/wp-includes/option.php on line 569
The plugin generated 2 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.
Please note I am very new to this....
<?php
/*
Plugin Name: Pure Tiger Hosting
Plugin URI: http://www.puretigerhosting.com/wordpressplugin
Description: Themes, Plugins and Support from within your admin panel.
Version: 1.00
Author: Pure Tiger Hosting
Author URI: http://www.puretigerhosting.com
License: GPL2
*/
?>
<?php
add_action('admin_menu','register_custom_menu_page');
add_action('admin_menu','register_my_custom_submenu_page');
add_action('admin_menu','register_my_custom_submenu_page2');
add_action('admin_menu','register_my_custom_submenu_page3');
Function register_custom_menu_page() {
add_menu_page('Pure Tiger', 'Pure Tiger','pure-tiger','add_users','','', 6);
}
/*-----------------------------Sub Pages--------------------------------------------*/
function register_my_custom_submenu_page() {
add_submenu_page( 'pure-tiger','Themes','Themes','PTthemes','','','my_custom_submenu_page_themes');
}
function register_my_custom_submenu_page2() {
add_submenu_page( 'pure-tiger','Plugins','Plugins','PTPlugins','','','my_custom_submenu_page_plugins');
}
function register_my_custom_submenu_page3() {
add_submenu_page( 'pure-tiger','Ask a Question','Ask a Question','question','','','my_custom_submenu_page_question');
}
/*-----------------------------Themes--------------------------------------------*/
function my_custom_submenu_page_themes() {
echo '<h3>Pure Tiger Themes</h3>';
}
/*-----------------------------Plugins--------------------------------------------*/
function my_custom_submenu_page_plugins() {
echo '<h3>Pure Tiger Plugins</h3>';
}
/*-----------------------------Support--------------------------------------------*/
function my_custom_submenu_page_question() {
echo '<h3>Pure Tiger Support</h3>';
}
?>
Try removing the open close php tags before your plugin declaration.
/*
Plugin Name: Pure Tiger Hosting
Plugin URI: http://www.puretigerhosting.com/wordpressplugin
Description: Themes, Plugins and Support from within your admin panel.
Version: 1.00
Author: Pure Tiger Hosting
Author URI: http://www.puretigerhosting.com
License: GPL2
*/
<?php
add_action('admin_menu','register_custom_menu_page');
//remaining code to follow....
Remove close ?> and open <?php tags after copyright notice. 2 newline prevent wordpress from sending headers.
<?php
/*
Plugin Name: Pure Tiger Hosting
Plugin URI: http://www.puretigerhosting.com/wordpressplugin
Description: Themes, Plugins and Support from within your admin panel.
Version: 1.00
Author: Pure Tiger Hosting
Author URI: http://www.puretigerhosting.com
License: GPL2
*/
add_action('admin_menu','register_custom_menu_page');
add_action('admin_menu','register_my_custom_submenu_page');
Check if this plugin trys to write a cookie.
If this is the case, then your plugin has to be initiated BEFORE any html code processing.
So you have to initiate the plugin in the top of your index.php, before the <!doctype ... >
Some reading about cookies : http://php.net/manual/en/features.cookies.php