I’m having trouble adding a custom attribute data-page="home"
to the root <html>
tag of the homepage on my WordPress site.
First image. Here is the code to insert: data-page=”home”
The purpose is to indicate that this is the home page, and only on this page will the preloader be loaded.
Second image. Preloader targeting “Home” page
I’ve tried using the following code in my theme’s functions.php
file, but it doesn’t seem to be working as expected:
<span style="font-size: 14.4px;">function add_custom_data_attribute_to_home($output) {
if (is_home()) {
$output = preg_replace('/<html(.*)(?=>)/', '<html$1 data-page="home">', $output, 1);
}
return $output;
}
add_filter('language_attributes', 'add_custom_data_attribute_to_home');</span>
I’ve verified that I’m on the homepage when applying the code, but the data-page
attribute isn’t being added to the <html>
tag. Can anyone help me identify what might be going wrong or suggest an alternative solution? I greatly appreciate any advice you can provide.
Thank you for your time and assistance!
]]><script>
(function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,’script’,’https://www.google-analytics.com/analytics.js’,’ga’);
ga(‘create’, ‘UA-00000000-0’, ‘auto’);
ga(‘require’, ‘GTM-0000000’);
ga(‘send’, ‘pageview’);
</script>
[Moderator note: code fixed. Please wrap code in the backtick character or use the code button.]
]]>DOES ANY BODY PLEASE TELL ME WHY is this HAPPENING? and what could it be? I install “anti-malware scan ” plugin to check my site, but I need to know if this is something I should worry about or not, and how can I fix it.
I′m using GoodWork Theme.
Installed plugins:
AddtoAny Share Buttons
Contact form 7
JetPack
Krown Portfolio
SEO Redirection
WPBakery Visual Composer
WP-SpamShield
WooCommerce
WangGuard
THANK YOU FOR YOUR HELP
]]>I’m trying to add some code the the function.php of my child theme, but I’m not sure how to do it the right way as everytime I try, the website crashes.
I believe this code previously worked when I wasn’t using a child theme. I only noticed the other day that the custom code was removed during an update, so that’s why I now want to add it to the child theme’s function.php
I want to hide a category so I add:
action set_category_widget_parameters($args) {
$args[‘exclude’] = ‘154’;
return $args;
}
add_filter(‘widget_categories_args’,’set_category_widget_parameters’);
This is the function.php of the child theme:
<?php
/* —————————————————————————-
Newspaper 7 Child theme – Please do not use this child theme with older versions of Newspaper ThemeWhat can be overwritten via the child theme:
– everything from /parts folder
– all the loops (loop.php loop-single-1.php) etc– the rest of the theme has to be modified via the theme api:
https://forum.tagdiv.com/the-theme-api/*/
/* —————————————————————————-
add the parent style + style.css from this folder
*/
add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’, 1001);
function theme_enqueue_styles() {
wp_enqueue_style(‘td-theme’, get_template_directory_uri() . ‘/style.css’, ”, ‘6.1c’, ‘all’ );
wp_enqueue_style(‘td-theme-child’, get_stylesheet_directory_uri() . ‘/style.css’, array(‘td-theme’), ‘6.1c’, ‘all’ );}
Where do I add it or is there something wrong with the code?
Thanks!
]]>My current code reads:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
AddHandler application/x-httpd-php5 .php5 .php
Where does the new code belong? TIA!
]]>I’m trying to add code to my website (main page, and every page really) and I can’t find where to do so. I’m using the latest version of WordPress and I’m trying to add RevenueHits code to my page to set up advertisements. I just don’t see where to do it. Yes I’m beyond new to WordPress lol. Any and all help is greatly appreciated!
]]>I need to add follow code “thks” message: … how can I do it?
<!– Google Code for Formulario Conversion Page –>
<script type=”text/javascript”>
/* <![CDATA[ */
var google_conversion_id = 944644323;
var google_conversion_language = “en”;
var google_conversion_format = “3”;
var google_conversion_color = “ffffff”;
var google_conversion_label = “8gRwCOv-kV0Q48G4wgM”;
var google_remarketing_only = false;
/* ]]> */
</script>
<script type=”text/javascript” src=”//www.googleadservices.com/pagead/conversion.js”>
</script>
<noscript>
<div style=”display:inline;”>
<img height=”1″ width=”1″ style=”border-style:none;” alt=”” src=”//www.googleadservices.com/pagead/conversion/944644323/?label=8gRwCOv-kV0Q48G4wgM&guid=ON&script=0″/>
</div>
https://www.ads-software.com/plugins/contact-form-7/
]]>Old client site: vanstar.com
I am in the process of extracting a calculator function from an old site for a client, the function is mostly javascript plugged right into the template but also script called from the wp directory:
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/javascripts/jquery.shuffleLetters.js"></script>
I didn’t want to edit my template files So i downloaded a plugin that allows me to place javascript right into a page called: code embed.
The plugin works and the HTML / JS that I embeded is preforming how it is suppose to for the most part wit the exception of the last part that is utilizing the shuffleLetters.js script.
The main problem is the server is halting performance because it detects mod security issues generated through the script I am trying to run.
How do I prevent that?
The next issue is weather or not the code is calling the script in the directory correctly?
on page HTML:
<div class="entry">
<div class="page-title">
<h2>Compute Your Commute</h2>
</div>
<div class="page-entry">
<p>Calculate your cost of commuting in your car and compare with a VanStar commute. *</p>
<div id="calculator">
<form action="" method="">
<div class="calculator-container">
<h4>Your commute and driving habits.</h4>
<span class="stripe">
<label for="calc-commute-distance">What is your daily round trip commute distance in miles from home to work?</label>
<input type="text" name="calc-commute-distance" id="calc-commute-distance"><br>
</span>
<span>
<label for="calc-work-days">How many days per month do you normally work? (fulltime=21)</label>
<input type="text" name="calc-work-days" id="calc-work-days"><br>
</span>
<span class="stripe">
<input type="submit" id="calc-submit" value="Submit">
</span>
</div>
</form>
<div class="calculator-container three-quarter">
<h4>Your Commute Expense in Personal Car</h4>
<span class="stripe">
<label for="calc-fuel-cost">Your monthly fuel costs</label>
<input type="text" name="calc-fuel-cost" id="calc-fuel-cost" value="$"><br>
</span>
<span>
<label for="calc-maint-cost">Your monthly maintenance and tire costs</label>
<input type="text" name="calc-maint-cost" id="calc-maint-cost" value="$"><br>
</span>
<span class="stripe" for="calc-month-direct">
<label>Your monthly direct commuting costs (including maintenance)</label>
<input type="text" name="calc-month-direct" id="calc-month-direct" value="$"><br>
</span>
<span for="calc-year-direct">
<label>Your yearly direct commuting costs (including maintenance)</label>
<input type="text" name="calc-year-direct" id="calc-year-direct" value="$"><br>
</span>
<span class="stripe" for="calc-van-month">
<label><strong style="color: red;">Estimated monthly VanStar costs</strong></label>
<input type="text" name="calc-van-month" id="calc-van-month" value="$"><br>
</span>
<span for="calc-van-year">
<label><strong style="color: red;">Estimated yearly VanStar costs</strong></label>
<input type="text" name="calc-van-year" id="calc-van-year" value="$">
</span>
<span class="stripe" for="calc-year-savings">
<label><strong style="color: red;">Estimated yearly savings by using VanStar</strong></label>
<input type="text" name="calc-year-savings" id="calc-year-savings" value="$">
</span>
</div>
</div>
</div>
</div>
</div>
<div id="calculator-savings">
You could save <div id="calculator-savings-figure">$0</div> a year by using VanStar!
</div>
<div class="clearfix"></div>
<p style="text-align: center;"><a href="vstar.jlbworks.net">Click here to return to the Home page.</a></p>
<p><small>* Calculations based on figures provided by AAA. <a href="https://newsroom.aaa.com/tag/your-driving-costs">Read more here..</a></small></p>
%CODE1%
JS in a custom field:
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/javascripts/jquery.shuffleLetters.js"></script>
<script type="text/javascript">
(function($){
$('#calculator #calc-submit').on('click', function(){
var $this = $(this),
$commuteDistance = $('#calc-commute-distance'),
$workDays = $('#calc-work-days'),
$fuelCosts = $('#calc-fuel-cost'),
$maintenanceCosts = $('#calc-maint-cost'),
$monthlyDirectCost = $('#calc-month-direct'),
$yearlyDirectCost = $('#calc-year-direct'),
$monthlyVanCost = $('#calc-van-month'),
$yearlyVanCost = $('#calc-van-year');
$yearlySavings = $('#calc-year-savings');
$fuelCosts.val('$' +
Math.round($commuteDistance.val() * $workDays.val() * .1234)
);
$maintenanceCosts.val('$' +
Math.round($commuteDistance.val() * $workDays.val() * .054)
);
$monthlyDirectCost.val('$' +
Math.round(($commuteDistance.val() * $workDays.val() * .1234) + ($commuteDistance.val() * $workDays.val() * .054))
);
$yearlyDirectCost.val('$' +
Math.round((($commuteDistance.val() * $workDays.val() * .1234) + ($commuteDistance.val() * $workDays.val() * .054)) * 12)
);
$monthlyVanCost.val('$' +
Math.round($commuteDistance.val() * $workDays.val() * .43 / 9)
);
$yearlyVanCost.val('$' +
Math.round(($commuteDistance.val() * $workDays.val() * .43 / 9) * 12)
);
$yearlySavings.val('$' +
Math.round(((($commuteDistance.val() * $workDays.val() * .1234) + ($commuteDistance.val() * $workDays.val() * .054)) * 12) - (($commuteDistance.val() * $workDays.val() * .43 / 9) * 12))
);
$('.calculator-container.three-quarter, .calculator-container.three-quarter .stripe').animate({
'width' : '700px'
}, 300, function(){
$('#calculator-savings').fadeIn();
$('#calculator-savings-figure').shuffleLetters({
'text' : $yearlySavings.val()
});
});
return false;
});
})(jQuery);
</script>
]]>