Add comments to wordpress inspect element page - wordpress

As the title says, I want to add some sort of signature with comments on my wordpress index file, thing is - there are 30 different index files and none of them seems to work

If I understand correctly, it'll just be a case of adding some HTML comments (not PHP comments as they won't show in the source code) in your theme files. Bear in mind that editing a theme won't work if someone else made it and releases updates to it as it'll overwrite your changes if you update it.
The best place to add in the comments is to either open the header.php file and place your HTML comments after the opening <body> tag. If your theme doesn't include a header file, you could always add your comments to the top of your themes index.php file instead.
Your theme should be located within /wp-content/themes/YOUR-THEME/.
Alternatively, you could also place HTML comments between the <head> tags of your theme so they show up a bit higher in the source code. To do this, it's probably best to use an action hook instead. Place this in your themes functions.php file:
add_action( 'wp_head', 'add_signature_to_theme', 1, 0 );
function add_signature_to_theme() {
?><!-- Welcome to my website. --><?php
}
The wp_head action hook documentation is useful to have as reference as well if you'd like a bit more information on what it is and what it does.

Related

Drupal basic page doesn’t seem to use page.tpl.php

Title says it really. Basic pages created in Drupal don’t seem to use the page.tpl.php file as a template.
If I edit the html.tpl.php file, those changes apply to every page, and it causes errors when I load a basic page.
I have also tried to copy the page.tpl.php file and name it page—basic-page.tpl.php to no avail.
Any idea what’s going on?
Also, how do I go about changing the page_top variable to include more content?
Lastly, the default page.tpl.php file has $page variables and things like $page_top and the like.
How would I call the title from the page only and the body text of a page only?
I’m using Drupal 7 and a custom sub theme.
The aforementioned files are in the template folder of the theme and I did clear caches when I added them.
Add $conf['theme_debug'] = TRUE; in settings.php and clear cache, reload page and check view source.
It will display the template file suggestions.
page.tpl.php file common for all pages. Just print anything to the tpl and run any node of basic page as well as other content type page and check if its working or not. If page.tpl.php not working for basic page only, then check your template.php file.
For print a page title just need to use following code:
<?php print $title; ?>
For print body text you need to use following:
<?php print render($page['content']); ?>
This may depend on the theme you are using. But I guess you are actually meaning page--page.tpl.php (double dashes). Which will be taken into account after you added the following snippet to your theme's template.php. Replace MYTHEME with your theme's machine name.
function MYTHEME_preprocess_page(&$variables) {
if (isset($variables['node']->type)) {
// If the content type's machine name is "my_machine_name" the file
// name will be "page--my-machine-name.tpl.php".
$variables['theme_hook_suggestions'][] = 'page__' . $variables['node']->type; // (double underscores)
}
}
See Template (theme hook) suggestions, where I also got above snippet from.
active theme debug for inspecting the template source and you get a different suggestions to user it (just avoid using node/nid).
commend drush to enable theme debug drush vset theme_debug 1

WordPress Template "X": Change html inside of <head>

I'm pretty new to WordPress and want to remove some unneeded js/css files that are loaded inside of the html-head of the page.
In wp-content/themes/x/framework/views/header/base.php I found the following code:
<head>
<?php wp_head(); ?>
</head>
This obviously doesn't help me at all. I have no idea what WordPress' "wp_head()"-function does next. Isn't there some simple file where I can just write/edit simple HTML for the "head" somewhere?
wp_head() is a function that fires the wp_head action hook. Wordpress is built on action hooks and filters, which means that not only can plugins and themes add things to your setup through these hooks, but you have the ability to remove things as well. Most of this is done programmatically (in PHP) instead of there just being an html template, although that's not always the case... but it IS the case in your case.
Scripts and styles, for the most part, are enqueued through the wp_enqueue_scripts action hook. You'll want to perform your script removals here.
The problem is, you'll have to know the name the script was registered as before you can remove it. For instance, jQuery is registered as 'jquery'. Pretty simple, right? However, not all scripts are going to be that simple, and you'll have to browse through the code to find the registered handles (names) for those scripts. Styles are a bit easier, as when you inspect your page in the browser, styles will have an id attribute set to 'example-style-css'. Wordpress appends the '-css' to registered and enqueued styles, so the name of your style is actually 'example-style'.
In your theme's functions.php, you can dequeue scripts and styles so they won't be included on your page like so:
function stack_46669800_dequeue(){
wp_dequeue_script('the-script-you-want-to-remove');
wp_dequeue_style('the-style-you-want-to-remove');
}
add_action('wp_enqueue_scripts','stack_46669800_dequeue',100);
(Notice the 100 in the add_action function here... This is the 'priority', or the order in which all added actions are fired. Most are at 10, so I changed the priority here to 100 so this would be fired presumably later than whatever is enqueueing your unwanted scripts. You can't dequeue something that hasn't been enqueued yet.)

Load custom css after plugin css in wordpress

I'm trying add CSS to testimonial slider (3rd Party plugin) on my wordpress theme. But my custom CSS file loads before the plugin CSS file.
Is there a way I can make the my custom CSS load after the plugin CSS?
I don't want to make any changes to the Plugin code.
Edit:
I noticed that the plugin is using "wp_print_styles" to load it's css file.
You'll need to update your plugin code to do this the "proper way" I believe.
Since you need it to load last I would take the common path of utilizing the wp_enqueue_scripts hook/function to set a low priority for it being processed. This way you can guarantee that the HTML remains valid and that you are loading your styles and scripts after all the default ones within WordPress plugin's code:
function my_plugin_unique_style() {
$base = get_stylesheet_directory_uri();
wp_enqueue_style( 'style-my-plugin-style', $base.'/styles.css' );
}
add_action('wp_enqueue_scripts', 'my_plugin_unique_style', 11 );
Of course you will have to modify this to use your plugin's css file name but this is the basic way to do this and have valid markup. It's worth mentioning that if this still loads before another CSS file in the HEAD of the page you should bump up the number from 11 to some other higher number.
You can read more about wp_enqueue_scritps here.

Identify wordpress blocks

I am trying to edit a wordpress-theme (translations that are hardcoded in the theme etc) and stumble upon a problem here:
How do I identify, where a content block comes from?
Like, if my theme is constructed by 3 files post.php header.php and footer.php (which would make things pretty simple, but in my case it's quite some more files) and the content isn't set there consistently and the naming is neither "semantic", how could I identify that compiled block abc comes from header.php?
Is that something that can be done via Firebug/DevTools?
Although this question is specifically aiming at Wordpress as a system, the same problem occurs with other file-heavy systems like Typo3 or Magento. Isn't there some other routine then opening, searching all existing files?
Thanks for your answers
If your theme is translation-ready, you could try using Poedit. If not, you can identify where a block comes from knowing that:
Header.php: you'll find there all the strings that come in every page of your blog. Normaly Header.php includes all the code from the beginning of the HTML document until body, but it can be different from one theme to another. There may be diferrents headers, like header-gallery.php (for galleries) or similars.
Index.php: That's the index of your blog, normally it includes the code from the BODY of the html document for the index page.
Single.php, Page.php, Content.php, Aside.php or similars: They include the code for the body of every post/page type. For instance, single.php includes the BODY code for the single post. Sometiems, instead of single.php there are another options like content.php, content-wide.php or similars ("content-TypeOfPage.php"
Footer.php: It closes the HTML document for every post/page. Normaly it includes from the last lines before closing the BODY until the closing of the HTML tag.
Functions.php:: Take care editing this one. This file and the other files required/included on it include the code for the settings of the theme and any other functions implemented. For instance, the custom admin pages on the Dashboard are coded there.

insert in the head tag after wp_head

Using wordpress 2.9.2. I am loading my css files for plugins as they are being called, which ofcourse is after my header has been loaded. I want to insert the calls those css files in the HEAD tag of the page, which can be done if i get a hook which includes lines in the head after wp_head() has been called. Help !
Look at http://codex.wordpress.org/Plugin_API/Action_Reference/wp_head - the action is called wp_head.
You will want to use wp_register_style() to register your CSS file followed by wp_enqueue_style() to actually add it to the list of stylesheets that are output.
There is an example on that page, but replace 'wp_print_styles' in the example with 'wp_head'.
Have you tried echoing the styles or .css include the in a function passed into wp_print_styles API action hook?
If you are using your own theme, you can just put <style> tags in your header.php file pointing to the stylesheets you are using.
If you need a hook, it is called wp_head (check the Codex documentation on it).
The solution that worked for me was inserting the css files in head using output buffer.

Resources