I'm in the process of a building a small WordPress bottom right corner popup. I ran into some trouble. This is my first time building a WordPress plugin. Anyways, I can't figure out how to show it on the front static page of my website. Please help?
This is the only file I have in my Plugin folder. Where is my
mistake?
Here's my code:
<?php
/*
Plugin Name: My First Plugin
Plugin URL: http://www.martinshabacom.ipage.com/test
Description: An awesome facebook popup plugin that will amaze you!
Author: Martin
Version: 1.0
Author URL: http://www.martinshabacom.ipage.com/test
*/
add_action('admin_menu', 'myfirstplugin_admin_actions');
function myfirstplugin_admin_actions() {
add_options_page('MyFirstPlugin', 'MyFirstPlugin', 'manage_options', __FILE__, 'myfirstplugin_admin');
}
function myfirstplugin_admin()
{
?>
<style>
.wrap {
width:100%;
height:auto;
}
.popup {
position:fixed;
bottom:0;
right:0;
width:325px;
height:200px;
background-color:#09f;
}
</style>
<div class="wrap">
<h1>Hello World!</h1><br>
<h4>Hope you like my awesome popup!</h4>
</div>
<div class="popup">
<?php if(is_front_page()) {
Hello world
}
?>
</div>
<?php
}
?>
I think you want to add output to the footer using the wp_footer action, not the admin_menu. The wp_footer is used to add output when the wp_footer() method is called by your theme. It's a useful place for floating elements on the website.
So it would be
add_action('wp_footer', 'myfirstplugin_admin_actions');
and make sure your theme has the <?php wp_footer() ?> line somewhere appropriate.
Related
Hi everybody I have this Wordpress website that I want to transform into an AMP website, one of the challnging task is to rewrite the css in inline.
So in the wordpress framework we have this functions.php file and inside we have the wp_enqueue_style function.
/**
* Proper way to enqueue scripts and styles
*/
function wpdocs_mytheme_styles() {
wp_enqueue_style( 'style', get_stylesheet_uri() . '/css/style.css' );}
add_action( 'wp_enqueue_scripts', 'wpdocs_mytheme_styles' );
Basically Wordpress will give us this line on out front end pages
<link rel='stylesheet' id='style' href='Path_to/css/stle.css' type='text/css' media='all' />
Can I change this display mechanism to make Wordpress display the registered styles in **INLINE this way :**
<style amp-custom>
<!-- The content of the style.css -->
<!-- .... -->
</style>
Yeah basically i have a lot of these files and I don't want to make a static change by opening each one and copy/pasting content n the header any idea?
You could do like this:
<style amp-custom>
{% include "/assets/css/main.min.css" %}
</style>
OR,
<style amp-custom>
/* any custom styles go here. */
body {
background-color: white;
}
amp-img {
border: 5px solid black;
}
amp-img.grey-placeholder {
background-color: grey;
}
</style>
Reference : AMP-DEV
You need to add the styles directly to the page head using wp_head()
add_action('wp_head', 'my_custom_styles', 100);
function my_custom_styles()
{
echo "<style>*{color: red}</style>";
}
is there any specific reason why you want to make use of inline styling?
My File names:
1.) about.php
2.) styles.css
The same stylesheet is also applied to index.php .
I want to style the section part of the page. I tried it by styling the [Eg.], .section-info{color:#555;}
but it didn't helped. Also should I change the stylesheet name to styles.php?
Thanks In Advance.
<?php
/* Website Header */
include ("include/header.php");
?>
<!-- Website Page-2 Main Content -->
<div class="wrapper">
<section>
<div class="section-info">
<h2>About Us</h2>
<p>blah...blah...bllah....</p>
</div>
</section>
</div>
<?php
/* Website Footer */
include ("include/footer.php");
?>
Try to give it different class or inline style.
I had a similar problem. I created a function here which I use.
Then I use $page = getPage("ab") which would return about and then you can check what page is in use using the below:
<?php
$page = getPage("ab");
if ($page == "about") { ?>
<style type="text/css">
.section-info {
background: #f00;
}
</style>
<?php } ?>
Put this code inside the <head> of your about.php page. This will apply whatever code you want to that page.
I want to make the header of this WordPress page taller. I found advice here that I should use the following code in the homepage template CSS file:
.full-container {
min-height: 390px;
}
The CSS file looks like this:
<?php
/**
* The template for displaying the home page panel. Requires SiteOrigin page builder plugin.
*
* Template Name: Page Builder Home
*
* #package vantage
* #since vantage 1.0
* #see http://siteorigin.com/page-builder/
* #license GPL 2.0
*/
get_header();
?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<div class="entry-content">
<?php
if ( is_page() ) {
the_post();
the_content();
}
else if( function_exists('siteorigin_panels_render') ) echo siteorigin_panels_render('home');
else echo siteorigin_panels_lite_home_render();
?>
</div>
</div><!-- #content .site-content -->
</div><!-- #primary .content-area -->
Where must I put the suggested code in?
In a Child Theme or wp-content/themes/vantage/style.css
The code you showed there as the CSS style is not the style at all, thats a costum page template named "Page Builder Home".
You should open style.css which is found directly on the theme folder. At the very end of style.css add the lines of css:
.full-container {
min-height: 390px;
}
If you dont know how to difference css files from php/html files then you definitely are in the wrong business and you should let the work be done by the pro-s.
having said that, hope my "solution" works for you.
How I can make a right sidebar for a wordpress theme and integrate with advanced search like the concept below:
sidebar.php
<?php
/**
* The sidebar containing the main widget area.
*
* #link https://developer.wordpress.org/themes/basics/template-files/#template-partials
*
* #package custom
*/
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
return;
}
?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</div><!-- #secondary -->
<?php if ( is_active_sidebar( 'sidebar-2' ) ) : ?>
<div id="tertiary" class="widget-area" role="supplementary">
<?php dynamic_sidebar( 'sidebar-2' ); ?>
</div><!-- #secondary .widget-area -->
<?php endif; ?>
style.css for sidebar
#secondary { /* left Sidebar */
width: 18rem;
margin-left: -67rem;
float: left;
position: relative;
}
#tertiary { /* right Sidebar */
width: 18rem;
margin-right: -23rem;
float: right;
position: relative;
}
How I can achieve it in an easy way?
Have a look at the WordPress Codex for information about customizing the sidebar. This page has a lot of information on it about the sidebar: https://codex.wordpress.org/Customizing_Your_Sidebar
If you are asking how to get a menu to expand from the side of the screen, there are many different CSS/JavaScript implementations, but perhaps something like this jQuery Slick Plugin might help: http://www.designchemical.com/lab/jquery-slick-plugin/examples/
If you are asking how to create the custom search functionality, then that is going to be very dependant on the plugins you are using and what you are searching for. This article does give a good overview of getting started with customised search capabilities and custom search forms in WordPress: https://premium.wpmudev.org/blog/build-your-own-custom-wordpress-search/
If you already have your sidebar.php set up in your template file where you want it; it could be index.php,single.php,page.php or whatever
I see two ways of doing it
1 - Install some fancy search plugin and add it your sidebar using Dashboard - Appearance - Widgets area
2 - In your Widget area you can add Html content where you will have your search form OR hardcode it in your sidebar.php OR create search-form.php(where you will have your form) and include it in your sibedar.php or directly to the template file using get_template_part()
here are some useful links:
https://codex.wordpress.org/Function_Reference/get_search_form
https://codex.wordpress.org/Function_Reference/get_template_part
I am using a pre-existing jQuery popup plugin for a WordPress site. The popup works great but the only problem is the styling - it didn't include any sort of "overlay" in the design. Since I want the background to "grey out", I set out to adding some classes and styles to the css to make this happen, but am running into a wall.
Here was the original HTML:
<div id="messagebox" class="visiblebox">
<div id="message">message content</div>
</div>
And I added a div above that to create this HTML:
<div id="popupOverlay" class="visiblebox"></div>
<div id="messagebox" class="visiblebox">
<div id="message">message content</div>
</div>
Here is the JS - I added the 2nd line to the removeMessageBox function below after editing my HTML per above:
function removeMessageBox() {
jQuery(this).parent('#messagebox').removeClass('visiblebox').addClass('hiddenbox');
jQuery(this).parent('#popupOverlay').removeClass('visiblebox').addClass('hiddenbox');
return false;
}
function boardReady() {
jQuery('#closebox').click(removeMessageBox);
jQuery('#messagebox').css('visibility', 'visible');
}
jQuery(window).load(boardReady);
And here is some corresponding CSS:
div#popupOverlay.visiblebox {display: block;}
div#popupOverlay.hiddenbox {display: none;}
div#messagebox.visiblebox {display: block;}
div#messagebox.hiddenbox {display: none;}
Of course, it's not working. I barely know any JS so I'm not sure exactly what to add to the right function to get the same effect of the close action when clicked on the close link.
I see. Why don't you try this
function removeMessageBox() {
jQuery('#messagebox').removeClass('visiblebox').addClass('hiddenbox');
jQuery('#popupOverlay').removeClass('visiblebox').addClass('hiddenbox');
return false;
}
There is no need for all the jQuery traversing (i.e. using the .parents() method) as both elements have unique IDs. The problem with your code is that #popupOverlay is not a parent of closebox.