Where is the <title> set in wordpress - php

I am searching for the exact location in which file, where the <title> tag is being filled. Could anyone point me there?
I've searched all the sites I could find but I could not find it :(

well there are many title tags in the wordpress theme but i think what you are looking for is located in : wp-content/themes/theme_name/header.php
<title><?php wp_title( '|', true, 'right' ); ?></title>

The <title> tag can be found in the header.php file of a theme's base directory.
This generally calls the wp_title function, which according to the wordpress documentation, can be found in wp-includes>general-template.php
Wordpress Documentation

Normally the title tag is in the header.php
/wp-content/themes/(your theme name here)/header.php

The answers above are true for WordPress versions earlier than 4.1. There is actually a much easier, much more dynamic way of adding the title tag into WordPress that doesn't require hardcoding <title>.
If you have WordPress version 4.1 or later, you might want to check your functions file for: add_theme_support( 'title-tag' );
If that's in there, the title tag is being generated by WordPress.
https://codex.wordpress.org/Title_Tag

Related

Add filter body_class to header.php without body tag

In the theme check of my website I saw an error saying that the filter body_class was not found. I took a look at the support page of the plugin I´m using (https://support.fancyproductdesigner.com/support/solutions/articles/5000582912-using-the-debug-mode-to-inspect-any-missing-hooks-in-woocommerce-product-pages) and it says:
Missing hook: body_class
If you are seeing this information instead of the Product Designer:
Sorry! But the product designer is not adapted for your device. Please use a device with a larger screen!
It means an important hook is missing in your theme. You need to add following code to the body HTML tag in the header.php your theme.
<body <?php body_class(); ?>>
I tried to add the code to the header.php file, which has this content:
<?php
// =============================================================================
// HEADER.PHP
// -----------------------------------------------------------------------------
// The site header.
// =============================================================================
x_get_view( 'header', 'base' );
But honestly, for some reasons it doesn´t help. Can someone show me which is the right way to do it?
Many thanks
Yeah, that was my thought. The script is in effect already there, but the theme says anyway, that the code is missing.

How to add plugins to my custom wordpress theme?

I'm making a WordPress theme by myself since I'm working for the first time in Wordpress I've watched some tutorials about it.
I have page.php header and footer and ofc an index. I insert the content from the pages with this:
<?php echo get_post_field('post_content', $post->ID); ?>
but I tried the get_post in a while loop with same result..
Everything is fine but when I want to use a plugin I can't add to my page... When I insert the shortcode of it it shows only the shortcode string... There are some plugins where I can click a "view" option and it would show a page with my plugin (for example a calendar) but that page is empty...
When I activate an original theme it works instantly... So I'm sure something is missing from my theme something which can load the plugins but I couldn't find solution for it.
Any ideas?
Did you add the <?php wp_head(); ?> function before the head area of the html document is closing? It imports important scripts and styles from wordpress itself (and probably also from the plugins).
See here:
https://developer.wordpress.org/reference/functions/wp_head/
Before closing the body area, the template should also include
<?php wp_footer();?>
See here:
https://developer.wordpress.org/reference/functions/wp_footer/

Replacing html tags using regex and add_filter()

I want to replace the <h2 class="fusion-post-title"> tag with <h1> tag.
I've tested the regex on regex101.com and the capturing groups are there.
Is this proper way to do so? Maybe Wordpress is not triggering my add_filter()?
function replace_content($content){
$content = preg_replace('#<h2 class="fusion-post-title"(.*?)>(.*?)<\/h2>#si', '<h1 class="fusion-post-title"${1}>${2}</h1>', $content);
return $content;
}
add_filter('the_content','replace_content');
The title isn't part of the content, hence your filter doesn't work. Last time I checked a Theme Fusion theme, the function they were using for generating titles didn't apply an filters that you could hook onto, but they did suggest that there are theme options for changing the tag used. See you have a couple of options:
You can search through the theme for fusion-post-title and see what functions come up, and whether there's any filters or options that you can use. Unfortunately, as it's a premium theme I don't have a recent copy to hand to check, otherwise I'd point you in the right direction.
You can edit the theme templates directly: I'd recommend doing this to a child theme, not the theme files directly. For more information on setting up a child theme, you should refer to the codex.
Assuming you're going with option 2: once you've got your child theme set up (i.e. you've got your functions.php and styles.css), you can copy the relevant templates from the parent theme over to the child theme, and then edit them as you wish. If you take a look at Avada's single.php you'll notice something similar to:
<?php echo avada_render_post_title( $post->ID, false, '', '2' ); ?>
The last argument - 2 - is the heading level to use (i.e h2). Simply change that to 1 and you should be good to go. Or replace it entirely with your own markup:
<h1 class="post_title"><?php the_title();?></h1>
Repeat this for which ever templates are required.

Where is this stylesheet being loaded from?

I am having a problem with a site I am developing with wordpress.
It happened after upgrading to the latest version (4.7)
Anyway. Go to the site www.scientized.com (just dummy content for now), and go the source. At around line 124 you see the tag <style type="text/css" id="wp-custom-css"> and then after some css is loaded.
The thing is, is that this some of my old css code from way early. To make life easier and to isolate the problem I have delete all css in my child themes style.css as well as the custom css in the customizer, and delete jetpack just to be sure. Yet this css is being loaded from somewhere. I have file explored the crap out of my site trying to find where this is located, but couldn't find anything.
I have found that in the wp-includes/theme.php there is this function:
function wp_custom_css_cb() {
$styles = wp_get_custom_css();
if ( $styles || is_customize_preview() ) : ?>
<style type="text/css" id="wp-custom-css">
<?php echo strip_tags( $styles ); // Note that esc_html() cannot be used because `div > span` is not interpreted properly. ?>
</style>
<?php endif;
}
so this wp_get_customer_css() function is calling the old css from somewhere -- I tried to follow the functions back to see where - but my php is not that good and got lost. Does anyone know where this is being loaded from?
I think I need to know where the JetPack custom css location is. I have read it is generated dynamically -- so I am not sure how to go about the problem.
Edit: I dont get the text box in the custom css area in customizer. Where is this text located?
Edit: I dont get the text box in the custom css area in customizer. Where is this text located?
The Additional CSS content is stored in wp_posts database table as a separate record. It's post_type is set to custom_css. To find which post is assigned to the field, you need to look in the option theme_mods_{your theme's slug}.
For example, here is the one from my test Sandbox site which is running the Genesis Sample theme. The post ID is 31, per the key custom_css_post_id.
How do I check my site?
You can go directly into your database via phpMyAdmin and look in the wp_options table. Or...you can do this:
add_action( 'init', 'check_custom_css_post_id_theme_mod' );
function check_custom_css_post_id_theme_mod() {
var_dump( get_theme_mods() );
}
The above code will display the theme mods for your current theme. Note the one that is keyed as 'custom_css_post_id'. That one holds the ID to the post for the CSS.
How to Remove It
To remove a theme mod, you use remove_theme_mod( 'custom_css_post_id' );. See codex for the documentation on this construct. It will remove the binding between the Additional CSS. How? It deletes the sub-option.
Note, it does not delete the post record, meaning you'll have an orphaned record in wp_posts.
The wp-custom-css is loaded from custom css & js

Why my template directory being spit out from wp_head?

I have a site in development that seems to be spitting out my template directory from wp_head. It's driving me crazy.
I inherited this site and I'm trying to make it work. I don't know what I should be looking for in the files.
here's the site in question: http://discoverthebody.ca/test/
Can anyone help with what I should look for?
EDIT: To clarify, in my header.php, I've narrowed down the error to happening here:
<!-- wordpress head functions -->
<?php wp_head(); ?>
<!-- end of wordpress head -->
The stray template directory call is being output right after that comment, so I assume wp_head() is where it's happening.
I'm not entirely sure what is it. I happened to notice that you have the plugin woo e-commerce enabled. I've noticed that plugin has really gone downhill lately, and tends to do a bunch of random stuff as well as not even work. Try disabling that plugin and seeing if it helps.
If it doesn't, try disabling your plugins one-by-one. If that doesn't fix it, look in header.php in your theme directory. for a stray link in the HTML.
if I was in your shoes I would do a site-wide search (ie grep) for one of these:
bloginfo( 'template_directory );
bloginfo( 'stylesheet_directory' );
get_stylesheet_directory_uri()
get_template_directory_uri()
TEMPLATEPATH
see: http://codex.wordpress.org/Function_Reference/bloginfo

Categories