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
Related
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/
I'm working on a Wordpress theme, where I want to change the generated markup of the [product_category] WooCommerce shortcode. I browsed through the templates directory in the plugin, but can't find the file related to this particular shortcode.
So my question is, which files I have to copy to my template and modify to change the HTML outcome of [product_category]? (CSS modifications are already done, but I need to display a very different HTML markup, and I don't want to hack around with JS).
Also it would be better not to rewrite the whole function with a hook, but change the original HTML a bit (for example, set the background color based on a custom meta field).
Esiest way :)
add_shortcode('test','test_show_shortcode');
function test_show_shortcode( $atts ) {
echo do_shortcode('[products limit="100" columns="..." category="..."]');
}
[test]
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.
I have written a little PHP script that I have included via short-code into a WordPress page. Is it possible to only use a custom css file in the PHP script without it inheriting CSS elements from the WordPress theme?
If yes than how ?
Any styles included after the original stylesheet will override the previous styles (as long as they are qualified to the same level).
A better way of overriding styles would be to give your new page an ID and then in your new stylesheet you can use #NewID .cssSelectorToOverride {\*new styles\*}
This is a good article that can teach you about css selectors and precedence: http://www.vanseodesign.com/css/css-specificity-inheritance-cascaade/
Generally if the new style file is called after the previous file it will be over wridden, or else specify the style in the tag it self if its critical in some manner.
I hope this will do, if want more assistance provide example with your work.
thank you
open function.php file inside your root directory of WordPress theme. and just insert this function PFB, just change the directory, for js you don't need to connect a separate file because you can use footer.php and insert your js code in script tag it will work accurately.
add_action( 'wp_enqueue_scripts', 'radliv_child_enqueue_styles' ); function radliv_child_enqueue_styles() { wp_enqueue_style( 'custom-css-style', get_template_directory_uri() . '/inc/assets/css/custom.css' ); } ;
You have to do two things:
give your snippet a parent div id, say "#mySnippet"
At the bottom of your css file, ad a section for #mySnippet elements. It is important to be at the bottom so it can override other properties if you must
A custom CSS files won't always work with wordpress because the platform requires a certain file structure, and if I'm not mistaken, all your css code has to be in style.css. This is why your snippet code has to be in style.css at the bottom (preferably well isolated from the rest with a comment line).
Now all the elements that you need to change would simply be preceded by #mySnippet. For example, your P tags in the snippet should be targeted as such:
#mySnippet p {
property:value;
}
This should take care of it..
My question: Is there any way of showing the visitor's IP address in the title of a page on Wordpress? What I've done so far is this: My IP Lookup.
Is there any plugin or a tweak that I can do to?
Here's the file: Header.php
Please help!!
I'm the author of the theme and its framework. I'm just going to modify the code that Matthew gave you a bit. For future updates to the theme and framework, it's better if you can avoid actually editing header.php in your Child theme, but instead utilize the framework's hook system:
http://www.wpjumpstart.com/tutorial/primary-framework-action-hooks/
themeblvd_title is one of the framework's actions. It has a default function already hooked onto it that displays the title the way you see it now. What you want to do is fairly easy because you're not actually modifying that default function, but instead just adding onto the action.
If the concept of action hooks in general is completely foreign to you, definitely check out this article -- www.wpjumpstart.com/tutorial/actions/ -- Understanding these basic WordPress development concepts is really going to expand what you're going to be able to do moving forward with your customizations.
So to accomplish what Mathew said, you'd do the following from the functions.php of your Child theme:
function my_title_addon() {
if (is_page(10)) { //Check if we are on the correct page
echo '|'; //Just a spacer between the default title and your addition
do_shortcode('[shortcode]');
}
}
add_action( 'themeblvd_title', 'my_title_addon' );
There's also one big thing to note here, as well. I noticed on your site, you're using Alyeska 2.0. You should update to the latest version Alyeska 2.1 posted last week on ThemeForest, which incorporates v2.1 of the framework. Inside is a new sample child theme that incorporates a slightly modified structure, as outlined in this video -- vimeo.com/41331677
If you do not use this new child theme structure, the above code I posted will add your IP shortcode to the start of themeblvd_title, which isn't what you want. If you elect to keep your current theme version and Child theme structure, the above add_action needs to have a priority higher than the default 10 like this:
function my_title_addon() {
if (is_page(10)) { //Check if we are on the correct page
echo '|'; //Just a spacer between the default title and your addition
do_shortcode('[shortcode]');
}
}
add_action( 'themeblvd_title', 'my_title_addon', 11 ); // Higher priority so it comes after default title function
Here is how you can use a filter hook to modify the title.
Add this in a theme functions.php file or one of your own plugins:
add_filter( 'wp_title', 'add_ip_to_title', 10, 3 );
function add_ip_to_title($title, $sep = '', $location = '') {
return $title . $sep . "visitor IP info here";
}
https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_title
Edit your header.php file in your theme. That is where the tag is generated. It should be wp-content/themes/alyeska-child/header.php or if it isn't there wp-content/themes/alyeska/header.php.
If you post the code that is generating your title (or your header.php file if you can't tell), we can tell you where to add it specifically.
If the IP info is generated via a shortcode, you can use do_shortcode('[shortcode]) in your PHP to run the shortcode directly with PHP.
If you wanted to do this on just one page, you would have to detect the correct page and conditionalize the change to the title. You need to know a page identifyer for the page you want, but you would use something like:
<title>
<?php
themeblvd_title();
if (is_page(10)) { //Check if we are on the correct page
echo '|'; //Just a spacer between the default title and your addtion
do_shortcode('[shortcode]');
}
?>
</title>
More information on is_page: http://codex.wordpress.org/Function_Reference/is_page
To add to some of the other answers, to get their IP address, it could vary a little bit depending upon your server environment. Just make a file called test.php and put it in a web accessible place:
<?php
echo phpinfo();
?>
Then, look for a place where you can retrieve the user's IP address. If your PHP is running in a reverse proxy, unfortunately, the normal place will just have localhost's IP. But there are a lot of other environmental variables you can grab the IP from. Here are the places to check:
"Apache Environment" or "HTTP Headers Information" or under the "PHP Variables" section.
Then, if you see the real IP address (compare the address shown on the info page with what you might get from whatismyip.com) then you can access that value in the function described above by drew010 using one of PHP's predefined variables.