R
R
RobShneider2020-01-18 09:12:18
CMS
RobShneider, 2020-01-18 09:12:18

How to pin a block in Worddress so that it is on all pages?

For example, a footer or menu is always on the pages and when you create a new one, it also appears

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
Leonid, 2020-01-18
@easycode

Add the code to the functions.php file in the active theme folder (you can add the code to the end of the file, but before the closing tag: ?> - if it is there, and if it is not there, then just to the end of the file):

register_sidebar(array(
        'name' => 'Мой блок',
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '<div class="title">',
        'after_title' => '</div>',
    ));

further, you need to decide where your block will be located - in what place on the page, if in the footer - then look in the footer.php file , if in the header - then maybe header.php . Everything here is very subtle and depends on the specific theme, because theme developers can be weird as they like - they have complete freedom in this, in footer.php or header.php - there may not be any HTML code within which you should act. Then you will have to look in the code of other files for the right place for your block and when you find it, paste it there: again, if you paste it inside the php code, then the <?php and ?> descriptors will not be needed - otherwise you will get either an error or unnecessary characters Online. on y next go to
Appearance / Widgets and there will appear a column with the name: "My block" - add the widget you need there and that's it - somehow)
But! Without at least minimal knowledge of HTML and an understanding of how WordPress themes work from the inside, it will be difficult to figure it out. Install at least the same Sublime Text editor, add the folder with your theme there and using Ctrl + Shift + F you can search for the HTML piece of code you need in all the files of this folder, so sometimes you have to be smart to find where the theme creators hid the surrounding place I need HTML code.

D
DooX, 2020-02-27
@DooX

as others said, everything is correct, you need to know at least html
and then there are 2 questions.
if the block is the same and static content, then this is done quickly and easily.
we hang this block on the footer or header hook in function.php
, this is a more difficult solution, since the header.php or footer.php file, depending on the theme, may be different for the pages. but get_header or its equivalent for the footer will be the same in 98%.

dd_action( 'get_header', 'action_function_name_1277' );
function action_function_name_1277( $name ){
  тут пишем то что хотим вывести но если юзаем тупо html то не забыть закрыть php и потом открыть его заново
или через echo ""; 
}

but if you want to edit this content through the admin panel, then yes, you can make a sidebar as Leonid pointed out , but again create a function and hang caps or footers on the hook, this will eliminate unnecessary gestures

T
tuxfighter, 2020-01-18
@tuxfighter

Add this "block" to the appropriate template (footer.php, header.php, page.php)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question