Wordpress Some Content in header file not outputting - wordpress

I'm developping a Wordpress website, and I need to display conditionnal content in header file, just after opening body tag.
If I call exit(); just after my condition, the code is outputted correctly, so I know condition is working and I'm in the right file. Then I remove the call to exit(); and code is not outputted.
Theme is Divi / Divi-Child, I removed all plugins to be sure (renamed the plugins folder to _plugins), no cache in effect.
I looked at both functions.php and child/functions.php, I don't see any 'after content' functions that would clean/remove the code, although I suspect this is what's happening.
Even the HTML comments are striped ()
</head>
<body <?php body_class(); ?>>
<!-- Advertising -->
<?php
$bool = is_sidebar_active('wallpaper-advertising');
//var_dump($bool);
if($bool){
//exit();
?>
<script>
jQuery(document).ready(function($){
if(jQuery('#ad_habillage').length>0){
jQuery('#adbg, .wallpaper_spacer').show(0);
}else{
jQuery('body').addClass('deactivate_wallpaper');
}
});
</script>
<div id="adbg">
<?php dynamic_sidebar('wallpaper-advertising'); ?>
</div>
<div class="wallpaper_spacer" style="">
<img src="<?= THEME_PATH ?>/media/img/994x112Transparent.gif" border="0" alt="Cliquez ici" title="Cliquez ici">
</div>
<div class="big_wallpaper_wrap_bg">
<div class="big_wallpaper_wrap">
<?php } ?>
<!-- End Advertising -->
Any help is welcome.

I found out using QueryMonitor, it shows templates in use, and header.php was replaced by another file in the theme folder. I moved my code there and it's all fine.

Related

in_category method in wordpress and script tags - AdjacentHTML

I am trying to show .gif banner on a posts only within specific category after first paragraph in wordpress, so I my code in loop-single.php looks like:
<?php if(in_category('my_category')){ ?>
<script>
const par = document.querySelector('p');
par.insertAdjacentHTML('afterend', '<div><img src="some_gif" alt="" class=""></div>')
</script>
<?php } ?>
But it doesn't work as expected. Anyone have an idea? Or may be some other solution that not recquires installing additional plugins (not that I don't want to, most of them just slow the site down).
Thank you
edit: 'after first paragraph' added
So, I found a way, firstly I needed to check if the post is in wanted category, than create a function and call it afterwards. The code is set in single-loop.php file in my template:
<?php if(in_category('my-category')){ ?>
<script type="text/javascript">
function krasAd() {
const par = document.querySelector("p");
par.insertAdjacentHTML('afterend', '<div><img src="my-gif" alt="" class=""></div>')
};
krasAd();
</script>
<?php } ?>
There was also one way to check if you have a string in URL that only recquires JS. But it recquires you to have properly created URL structure, for example: domain.com/category/post
If I had category in my posts URL I would use code below, the code is set before closing footer tag in my single-loop.php template file:
<script type="text/javascript">
if (window.location.href.indexOf("my-string") > -1) {
const par = document.querySelector("p");
par.insertAdjacentHTML('afterend', '<div><img src="my-gif" alt="" class=""></div>')
}
</script>

Bootstrap collapse stops working when switching field type to WYSIWYG

I'm creating a FAQ page on my wordpress site. I am using bootstrap 4.0's collapse component and ACF Pro to build the page.
On the back end, an admin can add questions and answers. The answers are to be hidden on the front end until a user clicks on the question to toggle the answer. Originally the answer field was a text area. All was working great! But when I changed the answer field type to be a WYSIWYG editor, the collapse functionality stopped working altoghether and the answers are not hidden or collapsible. Does anyone know how to solve this issue?
Thanks in advance, code snippet below.
<?php while( have_rows('topic_information') ): the_row();
$question = get_sub_field('question');
$answer = get_sub_field('answer');
$counter++;
?>
<div class="question-btn collapsed" data-toggle="collapse" data-target="#<?php echo $counter; ?>" aria-expanded="false" aria-controls="<?php echo $counter; ?>">
<div class="question">
<p class="question-text">
<?php echo $question; ?>
</p>
<div class="toggle-status"></div>
</div>
<div class="answer">
<p id="<?php echo $counter; ?>" class="collapse" aria-labelledby="headingOne" data-parent="#accordion"><?php echo $answer; ?>
</p>
</div> <!--.answer-->
</div> <!--.question-btn-->
<?php endwhile; ?> <!-- WHILE ( have_rows('topic_information') -->
I've experienced this with bootstrap when the bootstrap.js, bootstrapcdn or bootstrap.min.js is referenced more than once on a page. For me the plugin I was using was also importing or referencing its own bootstrap.js or bootstrap.min.js file which it why it was happening to me.
I would try removing the bootstrap.js or bootstrap.min.js reference from the ACF Pro plugin if possible or try removing it from your project (since your plugin is already referencing it) to see if works.
If that doesn't work you might want to try doing it from javascript since it sounds like the faq is dynamically generated:
bootstrap collapse not working when creating dyanmically
Good luck

Wordpress Is there anyway to add specific class to home page body tag?

I am using a theme (Arcade Basic) in which the home page header image is resized differently from all other pages...
I would like to have the same header resizing on all pages included the home..
The resizing script is a .js script I don't want (I can't) to modify .
The resizing is triggered by the presence of the 'page' class in the body tag ..
# HOME PAGE
<body class="home blog only-on-home no-fittext basic">
# OTHER PAGES
<body class="page-template-default page page-id-1183 no-fittext basic">
If there anyway to add the 'page' class on the home page ?
Providing that you are using a specific page to act as your homepage and not just the default list of posts, you can add the following is_home() to check if you're on the homepage then add a class.
More information on the static front page setting.
<?php if ( is_home() ) : ?>
<body class="<?php body_class('homepage'); ?>">
<?php else : ?>
<body class="<?php body_class(); ?>">
<?php endif; ?>
you Can - but I can't say that treating all of your pages like a "page" won't come with bugs.
I would call the class something else.
find this in your header.php
<body <?php body_class('whatEverClassHere'); ?>>

wordpress custom page template based on a specific <div>

I want to know how to set up a custom page template. My website is based on many different widths. example for some pages I use a div called <div class="content-wrap ninecol clearfix"> but for another page I use <div class="text-centered twelvecol clearfix">.
I need to create a template so that I can easy create new pages based on those templates.
Below is my static html code that Ive done in dreamweaver.
<div class="content-wrap ninecol clearfix"> <!--I want to make a template based on this div so I can just add new text in the future-->
<div class="content">
<h1 class="title">Om oss</h1>
<hr>
<div class="entry-content">
<h4>Vilka är Unified Sweden?</h4>
<p>Vi värnar starkt om vår unika företagskultur och ser den som vårt kraftfullaste
konkurrensmedel. Inom företaget har vi alltid arbetat hårt för att skapa den
stabila grund som vår företagskultur är byggd på. </p>
<p>All personal på Unified Sweden har många års erfarenhet av webbutveckling,
programmering, design och kundservice vilket gör oss unika då alla led inom kundbemötandet
vet exakt vad ni som företag behöver hjälp med.</p>
</div>
</div>
</div>
and this is what I came up with.
<?php
/*
Template Name: Test
*/
?>
<?php get_header(temp); ?>
<?php
// get_template_part( 'loop', 'index' );
?>
<div class="breadcrumbs">
<?php if(function_exists('bcn_display'))
{
bcn_display();
}?>
</div>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</div><!-- content-wrap -->
</div><!-- #content -->
</div>
</div><!-- .main -->
<?php get_footer(); ?>
Thank you for any kind of help or support.
Are you saying that for each template you want a different style? If yes you need to give different name at div id and then you should edit your style.css
#namediv{ }
to setup custom page template (if i understand your question correctly)
you create your page template in the theme directory which is active
and use the header the way you did
<?php
/*
Template Name: Test
*/
?>
you replace Test by whatever you want to use for the name (this name can have space)
then in the admin, you can select the template to use for the page by going to Admin > Page Attributes > Templates
Your new custom template should appear here
edit (following op comment)
then you could check which template is being use with
is_page_template()
http://codex.wordpress.org/Function_Reference/is_page_template
from within the header.php that would then load a specific css file
side note: you might also want to check the codex page: http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates as well as the dedicated wordpress stackexchange https://wordpress.stackexchange.com/
Template Name : Your page name
*/
you replace Test by whatever you want to use for the name (this name can have space) then in the admin, you can select the template to use for the page by going to Admin > Page Attributes > Templates Your new custom template should appear here

Drupal search block customizing

I have my block template block.tpl.php
<div class="block">
<?php print $content ?>
</div>
And I want to change block wrapper for search form
<div class="block search">
<?php print $content ?>
</div>
I'm trying to use block-search.tpl.php but it doesn't work
There is a feature in Drupal - you can override specific template(block-search.tpl.php) in theme when you override general template(block.tpl.php).
Other thing is that probably your cache is not cleared - try
And here you have some nice description how to check other things that could failed.

Resources